-
-
Save codecademydev/f48bdce369047300afab0ba62be5c2e4 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(bet, bet_amount): | |
print("You are currently playing Heads or Tails.") | |
#Used to determine heads or tails | |
num = random.randint(1, 2) | |
if num % 2 == 0: | |
num = "Heads" | |
print("The coin landed on " + str(num)) | |
elif num % 2 == 1: | |
num = "Tails" | |
print("The coin landed on " + str(num)) | |
#notifies player if they won or lost | |
if bet == num: | |
print("You won $" + str(bet_amount)) | |
print("Your new total is $" + str(money + bet_amount)) | |
return bet_amount | |
elif bet != num: | |
print("You lost -$" + str(bet_amount)) | |
print("Your new total is $" + str(money - bet_amount)) | |
print("If your bet turned out to be correct and it says you lost, check for spelling and/or capitalization errors. Thank you!") | |
return -bet_amount | |
def cho_han(bet, bet_amount): | |
dice_1 = random.randint(1, 6) | |
dice_2 = random.randint(1, 6) | |
total = dice_1 + dice_2 | |
if money >= 0: | |
print("You are also playing Cho Han.") | |
elif money<= 0: | |
print("You can't play Cho Han. You're out of money.") | |
return money | |
if total % 2 == 0: | |
total = "Even" | |
print("The dice roll was " + str(total)) | |
elif total % 2 == 1: | |
total = "Odd" | |
print("The dice roll was " + str(total)) | |
if bet == total: | |
print("You won $" + str(bet_amount)) | |
print("Your new total is $" + str(money + bet_amount)) | |
return bet_amount | |
elif bet != total: | |
print("You lost -$" + str(bet_amount)) | |
print("Your new total is $" + str(money - bet_amount)) | |
return -bet_amount | |
def war_card_game(player1_bet, player2_bet): | |
guest_money = 100 | |
player_1 = random.randint(1, 11) | |
player_2 = random.randint(1, 11) | |
if money >= 0: | |
print("You are also playing War.") | |
elif money <= 0: | |
print("You can't play War. You're out of money.") | |
return money | |
if player_1 > player_2: | |
print("Player 1. You won $" + str(player1_bet) + "!") | |
print("You now have $" + str(money + player1_bet)) | |
print("Player 2. You lost -$" + str(player2_bet) + "!") | |
print("You now have $" + str(guest_money - player2_bet )) | |
return player1_bet | |
elif player_2 > player_1: | |
print("Player 2. You won $" + str(player2_bet) + "!") | |
print("You now have $" + str(guest_money + player2_bet)) | |
print("Player 1. You lost $" + str(player1_bet) + "!") | |
print("You now have $" + str(money - player1_bet )) | |
return -player1_bet | |
elif player1_bet == player2_bet: | |
print("It's a tie!") | |
return money | |
#Call your game of chance functions here | |
money += coin_flip("Tails", 10) | |
money += cho_han("Even", 20) | |
money += war_card_game(10, 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment