intro to python: using strings, am I on the right track? -


i brand new programming , wanting know if on right track. task follows:

write python script will, when run, prompt user “enter shape:” input variable (entered screen) string can be: square, rectangle, triangle, circle or pentagon. use if, elif, , else commands analyze shape has been entered. output should print on screen “you entered shape: ” please note: in order input string variable, may use command raw_input instead of input.

my code is:

which_shape = int(raw_input("enter shape (1-5): ")) shape = ['square', 'rectangle', 'triangle', 'circle', 'pentagon']  if 1<= which_shape <= 5:     print("you entered shape, ") , shape[which_shape - 1] else:     print("shape not found in list") 

since you're using python, it'll easier this:

which_shape = raw_input("enter shape") shape = ['square', 'rectangle', 'triangle', 'circle', 'pentagon']  if which_shape in shape:     print("your entered shape is: "+which_shape) else:     print("wrong shape entered.") 

but i'm guessing assignment requires determine shape was, gotta way:

if which_shape in shape:     if which_shape=="rectangle":         ## here         pass     elif which_shape=="triangle":         ## here         pass     elif which_shape=="square":         ## here         pass     elif which_shape=="circle":         ## here         pass else:     print("wrong shape entered") 

python lacks switch statements how you'd make such thing happen.


Comments