while loop with the if statement in python -


print ("selection of mode\n easy \n moderate \n tough") selection = int(input("please enter right choice!! > "))  while selection != '':     if selection == 1:         print("\ngoodluck")     elif selection == 2:         print('\nyou brave')     elif selection == 3:         print ('\nyou must kidding')     selection = int(input("please enter right choice!!! > ")) 

i making small program, new python have bit of understanding problem, need know error when user have typed in correct selection 1 or 2 or 3 should go in loop , run if statement. once done should exit. apparently not working perfectly.

print ("selection of mode\n easy \n moderate \n tough") selection = input("please enter right choice!! > ")  while selection != '':     if selection == '1':         print("\ngoodluck")         break     elif selection == '2':         print('\nyou brave')         break     elif selection == '3':         print ('\nyou must kidding')         break     selection = input("please enter right choice!!! > ") 

i doing goes through if statement want exit once first selection correct of if statement.

try this

print ("selection of mode\n easy \n moderate \n tough") selection = int(input("please enter right choice!! > "))  while selection != '':     if selection == 1:         print("\ngoodluck")         break     elif selection == 2:         print('\nyou brave')         break     elif selection == 3:         print ('\nyou must kidding')         break     selection = input("please enter right choice!!! > ") 

also there no need of input() multiple times.

print ("selection of mode\n easy \n moderate \n tough") while true:     selection = int(input("please enter right choice!!! > "))     if selection == 1:         print("\ngoodluck")         break     elif selection == 2:         print('\nyou brave')         break     elif selection == 3:         print ('\nyou must kidding')         break 

Comments

Popular posts from this blog

node.js - How to mock a third-party api calls in the backend -

node.js - Why do I get "SOCKS connection failed. Connection not allowed by ruleset" for some .onion sites? -

matlab - 0-by-1 sym - What do I need to change in order to get proper symbolic results? -