New website: http://www.cs.indiana.edu/classes/a202 Problem for today: Using the language of your choice write a program that asks the user for a name and current age (number of years) and writes back a report saying how old that person will be a year from now. Example: start> Welcome to the program. Type your name: .... (e.g., Larry Bird then hit enter) Type your age (in years): ... (e.g., 56) Well, Larry Bird, next year you will be 57! Then the program ends. Time: 5 minutes E-mail me the program Choices: perl, Python a) Python Log into silo. Then choose a place to write a program (a folder): ~/09101115 mkdir ~/09101115 cd ~/09101115 From here on create a file (pico one) make it executable and run it: -bash-3.2$ pwd /u/dgerman/09101115 -bash-3.2$ ls -ld one -rwxr-xr-x 1 dgerman faculty 34 Sep 10 11:38 one -bash-3.2$ cat one #!/usr/bin/python print "Howdy." -bash-3.2$ ./one Howdy. -bash-3.2$ Then we learn about raw_input(...) and the program becomes: -bash-3.2$ ./one Welcome to the program Name: Adrian Well, hello Adrian -- how are you today? -bash-3.2$ ./one Welcome to the program Name: President Obama Well, hello President Obama -- how are you today? -bash-3.2$ cat one #!/usr/bin/python print "Welcome to the program" name = raw_input("Name: ") print "Well, hello", name, "-- how are you today?" -bash-3.2$ So let's finish it: -bash-3.2$ cat one #!/usr/bin/python print "Welcome to the program" name = raw_input("Name: ") age = raw_input("Age: ") print "Well,", name, "you will be", int(age) + 1, "next year." -bash-3.2$ ./one Welcome to the program Name: Adrian Age: 9 Well, Adrian you will be 10 next year. -bash-3.2$ So Python cares about types and we had to convert. b) Perl -bash-3.2$ ls -ld two -rwxr-xr-x 1 dgerman faculty 337 Sep 10 12:29 two -bash-3.2$ cat two #!/usr/bin/perl print "Welcome to the Perl version of that program\n"; # name = raw_input("Name: ") print "Name: "; $name = ; chop($name); # that eliminates the newline that's collected by perl chop($name); chop($name); print "Age: "; $age = ; print "Well ", $name, " you will be ", $age + 1, " next year\n"; -bash-3.2$ ./two Welcome to the Perl version of that program Name: Adrian German Age: 9 Well Adrian Germ you will be 10 next year -bash-3.2$