Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 28, 2020 15:19
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/67c9a4da521863ac7b0aed1c2749023c to your computer and use it in GitHub Desktop.
Save codecademydev/67c9a4da521863ac7b0aed1c2749023c to your computer and use it in GitHub Desktop.
Codecademy export
import random
money = 100
#Write your game of chance functions here
#pay off function with print out and updated balance
def pay_off(wager, outcome):
balance = 0
if outcome == True:
balance += balance + wager
print("You won ${0} dollars this bet, your up {1}.".format(wager, balance))
else:
balance += balance - wager
print("Sorry! You owe ${0} this round, your down {1}.".format(wager, balance))
#first game, heads or tails (random_walK), input wager and 1 or 2
def random_walk(wager, call):
flip = random.randint(1, 2)
if flip == 1:
print("It's heads!")
if flip == 2:
print("It's tails!")
if flip == 1 and call.lower() == "heads":
print("You got it champ!, {} was right, you're up {}".format(call, wager))
elif flip == 2 and call.lower() == "tails":
print("You got it champ!. {} was right, you're up {}".format(call, wager))
else:
print("Sorry! You're down {}".format(wager))
#C'est travaille?
#random_walk(10, "Heads")
#Cho-Han game!
def Cho_han(wager, call):
dice_1 = random.randint(1, 6)
dice_2 = random.randint(1, 6)
outcome = dice_1 + dice_2
result = 0
if outcome % 2 == 0:
result = 1
print("Even!")
else:
result = 2
print("Odd!")
if result == 1 and call.lower() == "even":
print("Master predictor, you're now up {}".format(wager))
elif result == 2 and call.lower() == "odd":
print("Master predictor, you're now up {}".format(wager))
else:
print("Fortune favors the persistent! Give me {} bucks though.".format(wager))
#C'est travaille?
#Cho_han(45, "even")
### Testing the values of deck and cards
#deck = [[i] * 4 for i in range(1, 13 + 1)]
#card = [card for i in deck for card in i]
#print(deck)
#print(card)
def random_card(wager):
deck = [[i] * 4 for i in range(1, 13)]
cards = [j for i in deck for j in i]
#random choice of card from deck. Probability of choosing same card = 0, second code line
#card1 == the player / card2 == the computer
card1 = random.choice(cards)
cards.remove(card1)
card2 = random.choice(cards)
cards.remove(card2)
#let the games begin
if card1 > card2:
print("You drew a {}, which beats a {}. You won ${}!".format(card1, card2, wager))
elif card1 < card2:
print("You drew a {}, which losses to a {}. You lost ${}!".format(card1, card2, wager))
else:
print("It's a tie! You keep the wager!")
#random_card(60)
def roulette(wager, guess):
wheel = random.randint(0, 36)
#odd vs. even
red = []
#Logic for odd and even
if guess == int and guess == wheel:
print("{}! Nice playing, you're up ${}.".format(wheel, wager * 35))
return +(wager * 35)
elif guess == int and guess != wheel:
print("{}! Fortune favors the persistent friend".format(wheel))
return -wager
elif guess.lower() == "odd" and wheel % 2 != 0:
print("{} odd! Nice playing, you're up ${}.".format(wheel, wager))
elif guess.lower() == "even" and wheel % 2 == 0:
print("{} even! Nice playing, you're up ${}.".format(wheel, wager))
else:
print("{}! Fortune favors the persistent friend".format(wheel))
roulette(20, 9)
#Call your game of chance functions here
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment