-
-
Save codecademydev/aa576b163d47f3228fad5973caa5835f 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(player_choice, bet_amount): | |
global money | |
print ("GAME OF COIN FLIP") | |
if (bet_amount <= 0): | |
print("You can't bet 0") | |
elif (bet_amount > money): | |
print("You don't have enough money to place that bet.") | |
else: | |
print("Your bet was accepted") | |
int_result = random.randint(1,2) | |
if int_result == 1: | |
coin_result = "HEADS" | |
elif int_result == 2: | |
coin_result = "TAILS" | |
print ("The coin was flipped and it landed on... " + str(coin_result).upper()) | |
if player_choice.upper() == coin_result.upper(): | |
print ("You were CORRRECT and " + str(bet_amount) + " has been added to your balance") | |
money += bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
elif player_choice.upper() != coin_result.upper(): | |
print ("You were INCORRRECT and " + str(bet_amount) + " has been removed to your balance") | |
money = money - bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
def cho_han(player_choice, bet_amount): | |
global money | |
print ('GAME OF CHO HAN') | |
if (bet_amount <= 0): | |
print("You can't bet 0") | |
elif (bet_amount > money): | |
print("You don't have enough money to place that bet.") | |
else: | |
print("Your bet was accepted") | |
dice1 = random.randint(1,6) | |
dice2 = random.randint(1,6) | |
int_result = dice1 + dice2 | |
if int_result % 2 == 0: | |
cho_han_result = "EVEN" | |
elif int_result % 2 != 0: | |
cho_han_result = "ODD" | |
print ("The Dice were rolled... a " + str(dice1) + " and... a " + str(dice2)) | |
if player_choice.upper() == cho_han_result.upper(): | |
print ("You were CORRRECT... " + str(bet_amount) + " has been added to your balance") | |
money += bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
elif player_choice.upper() != cho_han_result.upper(): | |
print ("You were INCORRRECT... " + str(bet_amount) + " has been removed to your balance") | |
money = money - bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
def card_war(bet_amount): | |
global money | |
print ("GAME OF CARD WAR") | |
if (bet_amount <= 0): | |
print("You can't bet 0") | |
elif (bet_amount > money): | |
print("You don't have enough money to place that bet.") | |
else: | |
print("Your bet was accepted") | |
#Converts Players Card from numerical value to Card Value... Eg... 11 = Queen | |
def player_card_conversion(card_to_convert): | |
if card_to_convert == 1: | |
player_card_converted = "2" | |
return player_card_converted | |
elif card_to_convert == 2: | |
player_card_converted = "3" | |
return player_card_converted | |
elif card_to_convert == 3: | |
player_card_converted = "4" | |
return player_card_converted | |
elif card_to_convert == 4: | |
player_card_converted = "5" | |
return player_card_converted | |
elif card_to_convert == 5: | |
player_card_converted = "6" | |
return player_card_converted | |
elif card_to_convert == 6: | |
player_card_converted = "7" | |
return player_card_converted | |
elif card_to_convert == 7: | |
player_card_converted = "8" | |
return player_card_converted | |
elif card_to_convert == 8: | |
player_card_converted = "9" | |
return player_card_converted | |
elif card_to_convert == 9: | |
player_card_converted = "10" | |
return player_card_converted | |
elif card_to_convert == 10: | |
player_card_converted = "Jack" | |
return player_card_converted | |
elif card_to_convert == 11: | |
player_card_converted = "Queen" | |
return player_card_converted | |
elif card_to_convert == 12: | |
player_card_converted = "King" | |
return player_card_converted | |
elif card_to_convert == 13: | |
player_card_converted = "Ace" | |
return player_card_converted | |
#Converts Opponents Card from numerical value to Card Value... Eg... 11 = Queen | |
def opponent_card_conversion(card_to_convert): | |
if card_to_convert == 1: | |
opponent_card_converted = "2" | |
return opponent_card_converted | |
elif card_to_convert == 2: | |
opponent_card_converted = "3" | |
return opponent_card_converted | |
elif card_to_convert == 3: | |
opponent_card_converted = "4" | |
return opponent_card_converted | |
elif card_to_convert == 4: | |
opponent_card_converted = "5" | |
return opponent_card_converted | |
elif card_to_convert == 5: | |
opponent_card_converted = "6" | |
return opponent_card_converted | |
elif card_to_convert == 6: | |
opponent_card_converted = "7" | |
return opponent_card_converted | |
elif card_to_convert == 7: | |
opponent_card_converted = "8" | |
return opponent_card_converted | |
elif card_to_convert == 8: | |
opponent_card_converted = "9" | |
return opponent_card_converted | |
elif card_to_convert == 9: | |
opponent_card_converted = "10" | |
return opponent_card_converted | |
elif card_to_convert == 10: | |
opponent_card_converted = "Jack" | |
return opponent_card_converted | |
elif card_to_convert == 11: | |
opponent_card_converted = "Queen" | |
return opponent_card_converted | |
elif card_to_convert == 12: | |
opponent_card_converted = "King" | |
return opponent_card_converted | |
elif card_to_convert == 13: | |
opponent_card_converted = "Ace" | |
return opponent_card_converted | |
deck = [1,1,1,1,2,2,2,2,3,3,3,3,4,4,4,4,5,5,5,5,6,6,6,6,7,7,7,7,8,8,8,8,9,9,9,9,10,10,10,10,11,11,11,11,12,12,12,12,13,13,13,13] | |
player_card_pulled = random.randint(0,len(deck)) | |
player_card = deck[player_card_pulled] | |
player_card_converted = player_card_conversion(player_card) | |
del deck[player_card_pulled] #Removes Players Pick From Pool of available cards | |
print("You got a " + str(player_card_converted)) | |
opponent_card_pulled = random.randint(0,len(deck)) | |
opponent_card = deck[opponent_card_pulled] | |
opponent_card_converted = opponent_card_conversion(opponent_card) | |
del deck[opponent_card_pulled] #Removes Opponents Pick From Pool of available cards | |
print("Your opponent got a " + str(opponent_card_converted)) | |
if (player_card_pulled == opponent_card_pulled): | |
print ("It was a Tie... All bets are returned") | |
elif (player_card_pulled > opponent_card_pulled): | |
print ("You won... " + str(bet_amount) + " has been added to your balance") | |
money += bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
elif (player_card_pulled < opponent_card_pulled): | |
print ("You lost... " +str(bet_amount) + ' has been removed from your balance') | |
money = money - bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
def roulette(player_choice, bet_amount): | |
global money | |
print ("GAME OF ROULETTE") | |
if (bet_amount <= 0): | |
print("You can't bet 0") | |
elif (bet_amount > money): | |
print("You don't have enough money to place that bet.") | |
else: | |
print("Your bet was accepted") | |
def roulette_spin_conversion(number): | |
if number == 37: | |
number = "0" | |
return number | |
elif number == 38: | |
number = "00" | |
return number | |
else: | |
number = str(number) | |
return number | |
roulette_spin = random.randint(1,38) | |
roulette_result = roulette_spin_conversion(roulette_spin) | |
print("The roullete wheel was spun and landed on... " + str(roulette_result)) | |
if (roulette_spin == 37) and (player_choice == "0"): | |
print ("You picked a winner for a 35 to 1 payout... " + str(bet_amount * 35) + " has been added to your balance") | |
money = money + (bet_amount * 35) | |
print ("Your balance is now " + str(money)) | |
return money | |
elif (roulette_spin == 38) and (player_choice == "00"): | |
print ("You picked a winner for a 35 to 1 payout... " + str(bet_amount * 35) + " has been added to your balance") | |
money = money + (bet_amount * 35) | |
print ("Your balance is now " + str(money)) | |
return money | |
elif (str(roulette_spin) == str(player_choice)): | |
print ("You picked a winner for a 35 to 1 payout... " + str(bet_amount * 35) + " has been added to your balance") | |
money = money + (bet_amount * 35) | |
print ("Your balance is now " + str(money)) | |
return money | |
elif (player_choice == "EVEN") and (roulette_spin % 2 == 0): | |
print ("EVEN was correct for a 1 to 1 payout... " + str(bet_amount) + " has been added to your balance") | |
money = money + bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
elif (player_choice == "ODD") and (roulette_spin % 2 != 0): | |
print ("ODD was correct for a 1 to 1 payout... " + str(bet_amount) + " has been added to your balance") | |
money = money + bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
else: | |
print ("You didn't pick a winner " + str(bet_amount) + " has been removed from your balance") | |
money = money - bet_amount | |
print ("Your balance is now " + str(money)) | |
return money | |
#Call your game of chance functions here | |
coin_flip("Heads", 10) | |
print("--------------------------------------------------------------------------------------") | |
cho_han("eVen", 10) | |
print("--------------------------------------------------------------------------------------") | |
card_war (10) | |
print("--------------------------------------------------------------------------------------") | |
roulette("1", 10) | |
print("--------------------------------------------------------------------------------------") | |
roulette("ODd", 10) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment