Jan-30-2020, 10:42 AM
Hi Guys,
Still fairly new here, wondering why this loop is not working.. im trying to create a simple coin flip game. I know there is plenty of resource online for this and so many simple ways of doing this program however I'd like to finish up on what i have created without looking at the other ways. I think you'll see what i means when you see the code.
Any help would be much appreciated.
Sorry for the nooby questions.
Thank you!
Ryan :)
Still fairly new here, wondering why this loop is not working.. im trying to create a simple coin flip game. I know there is plenty of resource online for this and so many simple ways of doing this program however I'd like to finish up on what i have created without looking at the other ways. I think you'll see what i means when you see the code.
import random
coin = ('heads','tails')
user_choice = input("Heads or Tails? ")
game = 0
while True:
try:
if user_choice.lower() in ("heads","Heads", "HEADS"):
print("You have selected: Heads ")
break
elif user_choice.lower() in ("Tails","tails","TAILS"):
print("You have selected: Tails ")
break
except ValueError:
print("You can only choose Heads or Tails")
while True:
print ("Coin has landed on: " ,random.choice(coin))
if coin == user_choice:
print("winner")
game =+ 1
print(game)
else:
print("You lose")
breakIn my head this should work perfectly... however when i execute the code it says i lose everytime... even if i win!? Any help would be much appreciated.
Sorry for the nooby questions.
Thank you!
Ryan :)
