-
-
Save codecademydev/5f511fc6a8b9bda87d7653b1f8fd36f3 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 game_of_chance_001 (coinbet, moneybet): | |
num = random.randint (1, 2) | |
if num == 1: | |
coinreal = "Heads" | |
else: | |
coinreal = "Tails" | |
if coinbet == coinreal: | |
result001 = moneybet | |
print (("You win: " + str (moneybet) + "! And all your money is: " + str (moneybet + money) + " (" + str(coinreal) + ")")) | |
return result001 | |
if coinbet != coinreal: | |
result001 = -(moneybet) | |
print ("You loose: " + str (moneybet) + "! And all your money is: " + str (money - moneybet) + " (" + str(coinreal) + ")") | |
return result001 | |
def game_of_chance_002 (bet, moneybet): | |
cube1 = random.randint (1, 6) | |
cube2 = random.randint (1, 6) | |
cubesum = cube1 + cube2 | |
if cubesum % 2 == 0: | |
betreal = "Even" | |
else: | |
betreal = "Odd" | |
if bet == betreal: | |
result002 = moneybet | |
print ("You win: " + str (moneybet) + "! And all your money is: " + str (moneybet + money) + " (" + str(cubesum) + ")") | |
return result002 | |
if bet != betreal: | |
result002 = -(moneybet) | |
print ("You loose: " + str (moneybet) + "! And all your money is: " + str (money - moneybet) + " (" + str(cubesum) + ")") | |
return result002 | |
def game_of_chance_003 (gamerbet1, gamerbet2): | |
card1 = random.randint (1, 36) | |
card2 = random.randint (1, 36) | |
if card1 > card2: | |
result003 = gamerbet1 | |
print ("1th gamer win: " + str (gamerbet1) + "! His card is: " + str (card1) + ", 2th gamer card is: " + str (card2)) | |
return result003 | |
elif card1 < card2: | |
result003 = -(gamerbet1) | |
print ("2th gamer win: " + str (gamerbet2) + "! His card is: " + str (card2) + ", 1th gamer card is: " + str (card1)) | |
return result003 | |
elif card1 == card2: | |
result003 = gamerbet1 | |
print ("It is a Tie! No one won! " + " (" + str (card1) + ", " + str (card2) + ")") | |
return result003 | |
def game_of_chance_roulette_004 (gamerbet004, moneybet004): | |
print ("Player bet is: " + str(gamerbet004)) | |
red = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35] | |
black = [2,4,6,8,10,12,14,16,18,20,22,24,26,28,30,32,34,36] | |
green=[0] | |
number = random.randrange (0, 37) | |
print ("Number is: " + str(number)) | |
if number in red: | |
print ('Number is red') | |
color = "red" | |
else: | |
print ('number is black') | |
color = "black" | |
if number % 2 == 0: | |
print ('Number is even ') | |
result = "even" | |
else: | |
print ('Number is odd') | |
result = "odd" | |
# result in USD: | |
if gamerbet004 == number: | |
result004 = 100 | |
print ("The player has won! The reward is $ 100!") | |
return result004 | |
elif gamerbet004 == 0: | |
result004 = 50 | |
print ("The player has won! The reward is $ 50!") | |
return result004 | |
elif gamerbet004 == color: | |
result004 = 10 | |
print ("The player has won! The reward is $ 10!") | |
return result004 | |
elif gamerbet004 == result: | |
result004 = 8 | |
print ("The player has won! The reward is $ 8!") | |
return result004 | |
else: | |
result004 = -(moneybet004) | |
print ("Unfortunately, the player lost his bet!") | |
return result004 | |
#Call your game of chance functions here | |
print ("Heads or Tails game:") | |
print (game_of_chance_001 ("Heads", 10)) | |
print (" ") | |
print ("Cho-Han game:") | |
print (game_of_chance_002 ("Odd", 5)) | |
print (" ") | |
print ("A higher card game:") | |
print (game_of_chance_003 (3, 3)) | |
print (" ") | |
print ("Roulette:") | |
print (game_of_chance_roulette_004 (13,10)) | |
print (" ") | |
money += game_of_chance_001 ("Heads", 10) | |
print (money) | |
money += game_of_chance_002 ("Odd", 5) | |
print (money) | |
money += game_of_chance_003 (3, 3) | |
print (money) | |
money += game_of_chance_roulette_004 ("odd",10) | |
print (money) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment