[Tutor] (no subject)

Steven D'Aprano steve at pearwood.info
Sun Aug 14 19:20:06 CEST 2011


je.rees e-mail wrote:
> I would like this script to only have a choice of one these. I'm not sure
> how to do it. My example would be when someone types Good next to print how
> I want it to reply Thats nice. Anyone know how and if I am making more
> mistakes point them out please.


Consider this example:


def test():
     prompt = "Please type 'Thats nice'"
     answer = raw_input(prompt)
     if answer == "Thats nice":
         print "You have typed it accurately"
     else:
         print "I'm sorry, you have made a mistake"


Paste that into the interactive interpreter, then run:

test()


and follow the instructions. Does that help?



-- 
Steven


More information about the Tutor mailing list