Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 4, 2020 21:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codecademydev/7f8867640b16115dcdd3177b42a719af to your computer and use it in GitHub Desktop.
Save codecademydev/7f8867640b16115dcdd3177b42a719af to your computer and use it in GitHub Desktop.
Codecademy export
import random
#num = random.randint(1,10) #generates a random of [1,10] and stores it in variable <num>
money = 100
#Write your game of chance functions here
#Coin flipping simulation
num_coin = random.randint(1,2)
def coin_flip(guess, bet):
if bet > money:
return "Oh Honey you ain't rich enough"
elif bet <= 0:
return "Have you lost your mind?"
elif guess == num_coin:
return money + bet
elif guess != num_coin:
return money - bet
#Cho-Han simulation: guessing "0" is even, "1" is odd
num_dice_1 = random.randint(1,6)
num_dice_2 = random.randint(1,6)
cho_han_boolean = (num_dice_1+num_dice_2) % 2
def cho_han(guess, bet):
if bet > money:
return "Oh Honey you ain't rich enough"
elif bet <= 0:
return "Have you lost your mind?"
elif guess == cho_han_boolean:
return money + bet
elif guess != cho_han_boolean:
return money - bet
else:
return "You better check on that"
#Card-picking simulation
num_card_1 = random.randint(1,10)
num_card_2 = random.randint(1,10)
def card_picking(bet):
if bet > money:
return "Oh Honey you ain't rich enough"
elif bet <= 0:
return "Have you lost your mind?"
elif num_card_1 > num_card_2:
return money + bet
elif num_card_1 < num_card_2:
return money - bet
elif num_card_1 == num_card_2:
return 0
#Roulette simulation
ball_number = random.randint(0,36)
roulette_boolean = ball_number % 2
def roulette(guess, bet):
if bet > money:
return "Oh Honey you ain't rich enough"
elif bet <= 0:
return "Have you lost your mind?"
elif guess == "Even" and roulette_boolean == 0:
return money + bet
elif guess == "Even" and roulette_boolean == 1:
return money
elif guess == "Odd" and roulette_boolean == 1:
return money + bet
elif guess == "Odd" and roulette_boolean == 0:
return money
elif guess == ball_number:
return money + bet*35
elif guess != ball_number:
return money
#Call your game of chance functions here
print (coin_flip(1,50))
money += coin_flip(1,50)
#print (cho_han(0,30))
#money += cho_han (0,30)
#print (card_picking(40))
#money += card_picking(40)
#print(roulette("Even", 200))
#money += roulette("Even", 200)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment