'Why does the if statement always get the value of the last condition
import random
guess = input("Head or Tail? ")
head_tails = ["Head", "Tail"]
def coin_flip():
random_number = [random.randint(0,1)]
for rando in random_number:
if rando == 0:
answer = head_tails[rando]
elif rando == 1:
answer = head_tails[rando]
user_guess = ""
#User_guess is always "False", even though the user(input) guessed the right outcome...
if guess == "Head" and random_number == 0:
user_guess = "True"
elif guess == "Tail" and random_number == 1:
user_guess = "True"
else:
user_guess = "False"
if user_guess == "True":
print("You are right!")
print("It was:", answer)
elif user_guess == "False":
print("You guessed wrong! You guessed:", guess)
print("It was:", answer)
coin_flip()
Why does user_guess always equal "False"?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
