-
-
Save codecademydev/00a2856417a0d02d351eedcdcc51db26 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 heads_tails(call, bet): | |
if not isinstance(bet, int): | |
print("The bet must be a number!") | |
return 0 | |
elif bet > money: | |
print("You don't have enough money to bet " +str(bet) +"!") | |
return 0 | |
elif bet < 0: | |
print("You cannot bet with a negative number!") | |
return 0 | |
elif not isinstance(bet, int): | |
print("The bet must be a number!") | |
num = random.randint(1, 2) | |
call = call.lower() | |
if call == "heads" and num == 1: | |
print("It's Heads! You win, well done!") | |
return bet *2 | |
elif call == "tails" and num == 1: | |
print("Sorry it's Heads! Unlucky!") | |
return -bet | |
elif call == "tails" and num == 2: | |
print("It's Tails! You win, well done!") | |
return bet *2 | |
elif call == "heads" and num == 2: | |
print("Sorry it's Tails! Unlucky!") | |
return -bet | |
else: | |
print("Did you call Heads or Tails?") | |
return 0 | |
def cho_han(guess, bet): | |
if not isinstance(bet, int): | |
print("The bet must be a number!") | |
return 0 | |
elif bet > money: | |
print("You don't have enough money to bet " +str(bet) +"!") | |
return 0 | |
elif bet < 0: | |
print("You cannot bet with a negative number!") | |
return 0 | |
dice1 = random.randint(1,6) | |
dice2 = random.randint(1,6) | |
result = dice1 + dice2 | |
guess = guess.lower() | |
if result % 2 == 0 and guess == "even": | |
print(str(result) +"! An even number! You Win!") | |
return bet * 2 | |
elif result % 2 == 0 and guess == "odd": | |
print(str(result) +"! Sorry, that's even. You lose!") | |
return -bet | |
elif result % 2 != 0 and guess == "odd": | |
print(str(result) +"! An odd number! You win!") | |
return bet * 2 | |
elif result % 2 != 0 and guess == "even": | |
print(str(result) +"! Sorry, that's odd. You lose!") | |
return -bet | |
else: | |
print("You need to guess if the number is odd or even.") | |
return 0 | |
def high_card(bet): | |
if not isinstance(bet, int): | |
print("The bet must be a number!") | |
return 0 | |
elif bet > money: | |
print("You don't have enough money to bet " +str(bet) +"!") | |
return 0 | |
elif bet < 0: | |
print("You cannot bet with a negative number!") | |
return 0 | |
card1 = random.randint(1,13) | |
card2 = random.randint(1,13) | |
if card1 > card2: | |
print("Your card is higher! You Win!") | |
return bet * 2 | |
elif card1 < card2: | |
print("Sorry, your card is lower. You lose!") | |
return -bet | |
else: | |
print("It's a tie!") | |
return 0 | |
def roulette(guess, bet): | |
if not isinstance(bet, int): | |
print("The bet must be a number!") | |
return 0 | |
elif bet > money: | |
print("You don't have enough money to bet " +str(bet) +"!") | |
return 0 | |
elif bet < 0: | |
print("You cannot bet with a negative number!") | |
return 0 | |
num = random.randint(1,38) | |
if num == 37: | |
print("It's a 0! You lose!") | |
return -bet | |
elif num == 38: | |
print("It's 00! You lose") | |
return -bet | |
if isinstance(guess, int): | |
if guess > 36: | |
print("You need to guess a number between 1 and 36") | |
return 0 | |
elif num == guess: | |
print(str(num) +"! You guessed the correct number and win big!") | |
return bet * 20 | |
elif num != guess: | |
print(str(num) +"! You lose!") | |
return -bet | |
guess = guess.lower() | |
if num % 2 == 0 and guess == "even": | |
print(str(num) +"! An even number! You Win!") | |
return bet * 2 | |
elif num % 2 == 0 and guess == "odd": | |
print(str(num) +"! Sorry, that's even. You lose!") | |
return -bet | |
elif num % 2 != 0 and guess == "odd": | |
print(str(num) +"! An odd number! You win!") | |
return bet * 2 | |
elif num % 2 != 0 and guess == "even": | |
print(str(num) +"! Sorry, that's odd. You lose!") | |
return -bet | |
else: | |
print("You need to guess odd or even.") | |
return 0 | |
#Call your game of chance functions here | |
print("Play flip a coin.") | |
money += heads_tails("heads", -35) | |
print("You have "+str(money) +"\n") | |
print("Now play cho han!") | |
money += cho_han("Odd", "50") | |
print("You have "+str(money) +"\n") | |
print("Let's play high card.") | |
money += high_card(50) | |
print("You have "+str(money) +"\n") | |
print("Now for some Roulette!") | |
money += roulette("Odd", 5) | |
print("You have "+str(money) +"\n") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment