-
-
Save codecademydev/7aa62e7c5f9d7401a6f7d270a113fedc to your computer and use it in GitHub Desktop.
Codecademy export
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
money = 100 | |
#Write your game of chance functions here | |
def coin_flip(choose_side, bet_amount): | |
coin_outcome = random.randint(1, 2) | |
if bet_amount <= 0: | |
print("Your bet cannot be negative or equal 0! Bet again!") | |
return False | |
if bet_amount > money: | |
print("You don't have enough money! Bet again!") | |
return False | |
if choose_side == 1: | |
print("You've placed a $" + str(bet_amount) + " bet and have chosen Heads!") | |
elif choose_side == 2: | |
print("You've placed a $" + str(bet_amount) + " bet and have chosen Tails!") | |
else: | |
print("""Your choice should be either: | |
1 for Heads or 2 for Tails. | |
Choose again!""") | |
return False | |
if coin_outcome == 1: | |
print("It's Heads!") | |
else: | |
print("It's Tails!") | |
if coin_outcome == choose_side: | |
print("You've won and you've got $" + str(money + bet_amount) + "!") | |
return bet_amount | |
else: | |
print("You've lost and you've got $" + str(money - bet_amount) + ".") | |
return -bet_amount | |
def cho_han(guess, bet_amount): | |
dice1 = random.randint(1, 6) | |
dice2 = random.randint(1, 6) | |
if bet_amount <= 0: | |
print("Your bet cannot be negative or equal 0! Bet again!") | |
return False | |
if bet_amount > money: | |
print("You don't have enough money! Bet again!") | |
return False | |
if guess == "Even": | |
print("You've bet $" + str(bet_amount) + " on an Even number.") | |
elif guess == "Odd": | |
print("You've bet $" + str(bet_amount) + " on an Odd number.") | |
else: | |
print("You have to type either Odd or Even for your guess. Guess again!") | |
return False | |
if dice1 + dice2 % 2 == 0 and guess == "Even": | |
print("""Let's roll the dice! The sum on both dice is even. You've won! | |
You have $""" + str(money + bet_amount) + "!") | |
return bet_amount | |
elif dice1 + dice2 % 2 == 0 and guess == "Odd": | |
print("""Let's roll the dice! The sum on both dice is even. You've lost. | |
You have $""" + str(money - bet_amount) + ".") | |
return -bet_amount | |
elif dice1 + dice2 % 2 != 0 and guess == "Odd": | |
print("""Let's roll the dice! The sum on both dice is odd. You've won! | |
You have $""" + str(money + bet_amount) + "!") | |
return bet_amount | |
else: | |
print("""Let's roll the dice! | |
The sum on both dice is odd. You've lost! | |
You have $""" + str(money - bet_amount) + ".") | |
return -bet_amount | |
#Call your game of chance functions here | |
money += cho_han("Even", 50) | |
money += cho_han("Odd", 46) | |
money += cho_han("Same", 34) | |
money += cho_han("Odd", -45) | |
money += cho_han("Even", 666) | |
money += cho_han("Even", 23) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment