Issue
I would like this program to only accept as inputted text any of "yes ,"y", "Yes"
but for some reason when I input one of them nothing happens and the loop below doesn't seem to run:
import time
print ("Welcome to my first ever RPG! created 10/07/2016")
time.sleep(2)
begin = raw_input("Would you like to start the game?")
Start = False
if begin == ("yes" , "y" , "Yes" ):
Start == True
while Start == True:
player_name = raw_input("What would you like to name your character")
print ("welcome " + player_name.capitalize())
(PS: simplest solution preferred, I'm sort of new to python)
Solution
You could go with your original solution and just change it like so (not recommended):
if begin.strip() == "yes" or begin.strip() == "y" or begin.strip() == "Yes":
Or just check for containment in a tuple:
if begin.strip() in ("yes" , "y" , "Yes" ):
Or even better:
if begin.strip().lower().startswith('y'):
The .strip()
deals with any whitespace the user may have inputted.
And you also want to change
Start == True
to
Start = True
Because the former line is an equality test rather than assignment, so in your case Start
is always False.
Answered By - ifma
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.