https://www.codecademy.com/practice/projects/games-of-chance
Basically what the post title says. I’m tackling the games of chance project. I got through the coin flip function and it worked fine. Then I attempted the Cho Han game. When I would run that function I would always get “Unexpected EOF while parsing” error. So I looked up what that meant and it turned out it could means a number of things, but since syntax is usually what I mess up, I went through my code again. Still couldn’t find the issue. So I tried to run the function with cmd and it worked (although I would only ever get the else statement to print. After trying this a few times, I again started getting Unexpected EOF while parsing in CMD! So now I’m at my wits end. I just can’t figure the issue out. Gonna leave the code here in the hopes someone can find my error and give me some guidance. TIA!
import random
money = 100
#Write your game of chance functions here
def coin_flip(guess, player_bet):
outcome = random.randint(1, 2)
if money < player_bet:
print("You don't have enough money to make that bet!")
elif guess == "Heads" and outcome == 1:
print("Heads! You just won $" + str(player_bet) + "!")
elif guess == "Tails" and outcome == 2:
print("Tails! You just won $" + str(player_bet) + "!")
else:
return "You lose! You just lost -$" + str(player_bet) + "!"
def cho_han(guess, player_bet):
dice1 = random.randint(1, 6)
dice2 = random.randint(1, 6)
if money < player_bet:
return "You don't have enough money to make that bet!"
elif guess == "Even" and guess == dice1 + dice2 % 2 == 0:
return "It's Even! You won $" + str(player_bet) + "!"
elif guess == "Odd" and guess == dice1 + dice2 % 2 != 0:
return "It's Odd! You won $" + str(player_bet) + "!"
else:
return "Nope! You lost -$" +str(player_bet) + "!"