if statement - Basic Python Script If Statment -


i messing around basic magic 8 ball program , im trying make aloww yes or no questions thinking except questions have first word "will" or "do" how can make allows words ?

here script:

import random import time print "welcome magic 8 ball !" while true:     def magic8(a):         foo = ['yes', 'no', 'maybe', 'doubtful', 'try again']         random import choice         print choice(foo)       = raw_input("question: ")     if == "exit":         exit()     #if stament here     print "determining future..."     time.sleep(2)     magic8(a) 

if a.split(none, 1)[0].lower() in {'will', 'do'}:     print "determining future..."     time.sleep(2)     magic8(a) # function names not capitalized 

str.split() splits sentence on whitespace, str.lower should handle uppercase.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -