Create a week03 subdirectory in your cs21/class directory:
% cd
% cd cs21/class
% pwd
/home/your_user_name/cs21/class
% mkdir week03
Then, from within your week03 subdirectory copy over some python files
from my public directory:
% cd week03
% pwd
/home/your_user_name/cs21/class/week03
% cp ~newhall/public/cs21/week03/* .
% ls
ascii.py drop_letter.py format.py is_odd.py what_is_it.py
Once we have tested this, let's see what happens if the user enters 10000. How can we fix this?
$ cp charvalue.py alphavalue.py $ vim alphavalue.pyLet's change alphavalue.py so that in interprets input values differently than charvalue.py. Instead of 1 corresponding to the character encoded with ascii value 1, we will interpret 1 to correspond to the first character in the alphabet 'a', 2 to 'b', and 26 to 'z'. Our program will only encode letters between a and z. How can we change our program to do this? What about input values that are larger than 26 (again, we will ignore the case of bad input values that are less than 1 for now)? How can we handle these?
$ python ascii.py Enter a phrase: hello there h : 104 e : 101 l : 108 l : 108 o : 111 : 32 t : 116 h : 104 e : 101 r : 114 e : 101
This program takes as input a string and produces a new string cosisting of every other (even) character from the first Enter a phrase: I love computer science! The modified string is: Ilv optrsine
Once you get that working add code to check that the user correctly entered just a single character. If not, then print out an error message saying that the input is bad and quit the program by making a call to the exit function:
print "bad input" # come up with a better message than this exit()
Once you get that to work, lets add code to first check to see if the input value entered by the user is a valid int (e.g. the string "hello" is not a valid int value). If the input is not valid, print out an error message and exits. If it is valid, then print out a message indicating if it is an odd or even number.