python 3.x - How do I do user inputs -


what wish ask question user (user inputs) (answers: yes, no) if yes, happens, if no, else happens.

i.e: ask user if want have race in how fast can type compared computer. if yes, have race, if no, can continue else.

what looking input:

user_input = input('yes or no?: ') if user_input == 'yes':     print('you said yes!') elif user_input == 'no':     print('you said no!') else:     print('you said neither.') 

if want ensure user user inputs either yes or no can do:

while true:     user_input = input('yes or no?: ')     if user_input in ['yes', 'no']:         break     else:         print('that not valid option!')  if user_input == 'yes':     print('you said yes!') else:     print('you said no!') 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -