-
-
Save codecademydev/2add18ceb80973a9f144dcbb255f4eba 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 | |
num = random.randint(1,2) | |
money = 100 | |
#Write your game of chance functions here | |
#Coin flip game | |
def get_input(): | |
input1 = input("Heads or Tails?") | |
input2 = input("How much would you like to bet?") | |
return input1, input2 | |
def coin_flip(input1, input2): | |
global money | |
if input1 == "Heads" and num == 1: | |
money += int(input2) | |
print(f"You've won ${input2}") | |
return money | |
elif input1 == "Tails" and num == 2: | |
money += int(input2) | |
print(f"You've won ${input2}") | |
return money | |
else: | |
money -= int(input2) | |
print(f"You've lost ${input2}") | |
return money | |
def main(): | |
user_input1, user_input2 = get_input() | |
print(f"I choose {user_input1} with a bet of ${user_input2}") | |
myMoney = coin_flip(user_input1,user_input2) | |
print("My money: $",myMoney) | |
#main() | |
#This function doesn't work on Codecademy | |
def validate_bet (bet): | |
print ("You are betting: $" + str(bet)) | |
if bet > money: | |
print ("You don't have enough money make that bet") | |
return False | |
if bet <= 0: | |
print ("Bet must be bigger than 0 in order to play") | |
return False | |
return True | |
#Cho-Han | |
def roll_dice(guess, bet): | |
global money | |
if validate_bet(bet): | |
num = random.randint(1,6) + random.randint(1,6) | |
print("Your guess: " + guess) | |
print("You rolled a total of " + str(num)) | |
if num % 2 == 0: | |
result = "Even" | |
else: | |
result = "Odd" | |
if guess.lower() == result.lower(): | |
print(f"Amazing! You've just won ${bet}") | |
print ("Your current pool of money is $" + str (money + bet)) | |
return bet | |
else: | |
print(f"Sorry! You've lost ${bet}") | |
print ("Your current pool of money is $" + str (money - bet)) | |
return -bet | |
#Write your game of chance functions here | |
#roll_dice("Odd", 1) | |
#Card Picking game | |
def card_picking(bet): | |
global money | |
if validate_bet(bet): | |
card_deck = [i for i in range(1,14)]*4 | |
card1 = card_deck.pop(random.randint(0,52)) | |
card2 = card_deck.pop(random.randint(0,51)) | |
#print(card_deck) | |
print("Your card is: " + str(card1)) | |
print("My card is: " + str(card2)) | |
if card1 > card2: | |
print("You win $" + str(bet) + "!") | |
print("Total money: $" + str(money + bet)) | |
return bet | |
elif card2 > card1: | |
print("You lost $" + str(bet) + "!") | |
print("Total money: $" + str(money - bet)) | |
return -bet | |
else: | |
print("It's a tie!") | |
print("Total money: $" + str(money)) | |
return 0 | |
#Roulette | |
def validate_number(guess): | |
if guess not in range(1,37): | |
print("You must choose a number between 1 and 36") | |
return False | |
else: | |
return True | |
def roulette(guess,bet): | |
if validate_bet(bet) and validate_number(guess): | |
print("You are betting on number: " + str(guess)) | |
print("spinning the wheel...") | |
num = random.randint(5,6) | |
if num == 37: | |
print("The ball lands on 00!") | |
print("You lost!") | |
return -bet | |
else: | |
print("The ball lands on " + str(num)) | |
if num == 0 or num != guess: | |
print(f"Sorry! You've lost ${bet}") | |
print ("Your current pool of money is $" + str (money - bet)) | |
return -bet | |
elif num == guess: | |
print(f"Amazing! You've just won ${bet}") | |
print ("Your current pool of money is $" + str (money + bet)) | |
return bet | |
money += roll_dice("Odd",10) | |
money += card_picking(10) | |
money += roulette(17,10) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment