+ 1

Heads or Tails

I'm coding a coin toss game on my computer... I think I've got everything I need. But can someone tell me how to get user input? I think I need to use raw_data byt I'm not sure how to write it or limit the input to just heads or tails. Help would be greatly appreciated. Thank you

10th Jan 2018, 3:55 AM
Dank banker
Dank banker - avatar
2 odpowiedzi
+ 6
Something like this user_guess = input("heads or tails?\n") print("You entered", user_guess) if user_guess.lower() not in ("heads", "tails"): print("Try again but just enter 'heads' or 'tails'") quit() # carry on with the code to be run if the input is 'heads' or 'tails' Since Python is case sensitive, using the str.lower() method allows for entries like heads, Heads and HEADS
10th Jan 2018, 4:36 AM
David Ashton
David Ashton - avatar
+ 4
Maybe you were thinking of raw_input() from Python 2. In Python 3, just use the input() function: variable = input("Enter a number: ")
10th Jan 2018, 4:17 AM
LunarCoffee
LunarCoffee - avatar