create a program that should ask a user input either 0 (tails) or
1 (heads). Then the program will draw a coin flip. The program will declare the
user a winner if the result of the coin flip is equal to the user input. If the
user enters a value outside the given choices, it will display invalid choice.
import random
try:
choice = int(input("Enter your choice 0 (tail) or 1 (head): "))
except:
print('Invalide input')
exit()
if choice != 0 and choice != 1:
print('Invalide choice!')
exit()
coin = random.randint(0,1)
if choice == coin:
print('You win!')
else:
print('You lose.')
Comments
Leave a comment