Jan-30-2020, 02:26 PM
(Jan-30-2020, 02:16 PM)buran Wrote: How do you assign the value returned frominput
when you don't know what it will be?
I can write the code, but it will be more beneficial for you if you get it done yourself.
So, I think I have it.
""" Random Number generator game """ import random coin = ('heads','tails') game = 0 while True: user_choice = input("Heads or Tails? ").lower() if user_choice in ("heads","h"): print("You have selected: {}".format(user_choice)) user_choice = 'heads' break elif user_choice in ("tails","t"): print("You have selected: {}".format(user_choice)) user_choice = 'tails' break else: print("You can only choose Heads or Tails") continue coin_result = random.choice(coin) print ("Coin has landed on: " ,coin_result) if coin_result == user_choice: print("winner") game =+ 1 print(game) else: print("You lose")Now I have to put the bottom section back in the while loop so that it can be replayed instead of ending.
I also need to somehow keep track of the games won as it tends to always just say "1" instead of accumulating it.
Is this what you meant?
Thank you!