Feeds:
Posts
Comments

Posts Tagged ‘input’

Python HelloFriend Guide

The is a Helloworld tutorial for python. Follows the following steps to learn the fundamental of Python input and output:

1. create a folder to store your source code, for example:

mkdir -p ~/source/python/HelloFriend/src

2. change the current directory to the working folder, for example:

cd ~/source/python/HelloFriend

3. create the source code by the following command:

nano src/HelloFriend.py

4. In the nano environment, type the source code:

#!/usr/bin/python
def hello_friend():
	name=''
	while True:
		name=raw_input("What is your name (type 'quit' to quit) ? ").strip()
		if name.lower()=='quit':
			break
		print 'Hello, '+name+'!'
hello_friend()

5. press ctrl-x to leave and save the source code

6. Grant the Execution right to the python file:

chmod +x src/*.*

7. Run the program by the following command:

src/HelloFriend.py

8. As you run the program, you’ve been asked for your name repeatedly:

What is your name (type 'quit' to quit) ? Peter Pan
Hello, Peter Pan!
What is your name (type 'quit' to quit) ? quit

Read Full Post »

Ruby HelloFriend Guide

The is a Helloworld tutorial for ruby input and output. Follows the following steps to examine how ruby process console’s input and output:

1. create a folder to store your source code, for example:

mkdir -p ~/source/ruby/HelloFriend/src

2. change the current directory to the working folder, for example:

cd ~/source/ruby/HelloFriend

3. create the source code by the following command:

nano src/HelloFriend.rb

4. In the nano environment, type the source code:

#!/usr/bin/ruby
def hello_friend
	begin
		print "What is your name (type 'quit' to quit) ? "
		name=gets.chomp.gsub(/^\s+|\s+$/,'')
		if name.downcase=='quit'
			break
		end
		puts 'Hello, '+name+'!'
	end while true
end
hello_friend

5. press ctrl-x to leave and save the source code

6. Grant the Execution right to the ruby file:

chmod +x src/*.*

7. Run the program by the following command:

src/HelloFriend.rb

8. As you run the program, you’ve been asked for your name repeatedly:

What is your name (type 'quit' to quit) ? Peter Pan
Hello, Peter Pan!
What is your name (type 'quit' to quit) ? quit

Read Full Post »

Perl HelloFriend Guide

The is a Helloworld tutorial for perl input and output. Follows the following steps to examine how perl process console’s input and output:

1. create a folder to store your source code, for example:

mkdir -p ~/source/perl/HelloFriend/src

2. change the current directory to the working folder, for example:

cd ~/source/perl/HelloFriend

3. create the source code by the following command:

nano src/HelloFriend.pl

4. In the nano environment, type the source code:

#!/usr/bin/perl
sub hello_friend{
	while(true){
		print "What is your name (type 'quit' to quit) ? ";
		chomp($name=<STDIN>);
		$name =~ s/^\s*(.*?)\s*$/$1/;
		last if lc($name) eq 'quit';
		print "Hello, $name!\n"
	}
}
hello_friend

5. press ctrl-x to leave and save the source code

6. Grant the Execution right to the perl file:

chmod +x src/*.*

7. Run the program by the following command:

src/HelloFriend.pl

8. As you run the program, you’ve been asked for your name repeatedly:

What is your name (type 'quit' to quit) ? Peter Pan
Hello, Peter Pan!
What is your name (type 'quit' to quit) ? quit

Read Full Post »