Hi this is school work so please don't just give me the right answer but tell me what I have done wrong so I can go and correct it please. So my code works fine but there is one problem. When I type "Coin", the error message is displayed after it displays the coin flip. Here is my code:
def program():
error_message = "Answer not recognised!\nMake sure it is spelt right and starts with a capital letter."
Choice = input("Pick either 'Card' or 'Coin' ")
if Choice == "Coin":
import random
r = random.randint(1,2)
if r == 1:
print ("Heads!")
else:
print ("Tails!")
if Choice == "Card":
import random
card_number = random.randint(1,13)
if card_number == 1:
card_number = "Ace"
elif card_number == 11:
card_number = "Jack"
elif card_number == 12:
card_number = "Queen"
elif card_number == 13:
card_number = "King"
if Choice == "Card":
import random
card_suit = random.randint(1,4)
if card_suit == 1:
card_suit = "Hearts"
elif card_suit == 2:
card_suit = "Clubs"
elif card_suit == 3:
card_suit = "Diamonds"
else:
card_suit = "Spades"
if Choice == "Card":
print(card_number ,"of" , card_suit)
#else print error message
else:
print(error_message)
while flag:
program()
flag = input('Would you like to run the program again? [yes/no] ') == 'yes'
else:
print ("The program will now terminate.")
I have tried many different ways of trying to get around this but I cant figure it out. Remember this is school work so I would like help but not to be told the answer. Thanks