Skip to content

Instantly share code, notes, and snippets.

@codecademydev
Created February 27, 2020 13:52
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/0e32c6b0b2cac434e1fced94c08ca51f to your computer and use it in GitHub Desktop.
Save codecademydev/0e32c6b0b2cac434e1fced94c08ca51f to your computer and use it in GitHub Desktop.
Codecademy export
import random
money = 100
#Write your game of chance functions here
#Definieren der Funktion Flip Coin mit einem Wettbetrag, welchen man im Gewinnfall (richtiges Raten von Kopf oder Zahl)zu seinem Geld dazu bekommt und im Verlustfall (falsches Raten von Kopf oder Zahl) von seinem Geld abgezogen bekommt.
def flip_coin(bet,coin):
global money
num = random.randint(1,2)
if (num >= 0) and (num <= 1):
coin_result = "Heads"
elif (num > 1) and (num <= 2):
coin_result = "Tails"
if coin == coin_result:
money += bet
return "You won " + str(bet) + " Euros, because you guessed the coin result is " + coin + ". And that is right! Your new credit is " + str(money) + " Euros."
else:
money -= bet
return "You lost -" + str(bet) + " Euros, because you guessed the coin result is " + coin + ". But that is wrong. The coin shows " + coin_result + ". Your new credit is " + str(money) + " Euros."
#Definieren der Funktion Cho Han, bei welchem 2 Würfel gewürfelt und die Summe beider zusammenaddiert wird. Dann wird geguckt, ob die Summe gerade oder ungrade ist und dann mit der Schätzung des Spielers abgegelichen. Wenn der Spieler richtig lag, bekommt er seinen Wetteinsatz zu seinem Geld dazu. Wenn nicht wer der Einsatz abgezogen.
def cho_han(bet,dice):
global money
dice1 = random.randint(1,6)
dice2 = random.randint(1,6)
print("The dices are rolling...")
print()
print("The first dice shows the number: " + str(dice1) + ". The second dice" " shows the number: " + str(dice2) + ". Together that sums up to: " + str(dice1 + dice2))
if (dice1 + dice2) % 2 == 0:
dice_result = "Even"
elif (dice1 + dice2) % 2 != 0:
dice_result = "Odd"
if dice == dice_result:
money += bet
return "You won " + str(bet) + " Euros, because you guessed the dice result is " + dice + ". And that is right! Your new credit is " + str(money) + " Euros."
else:
money -= bet
return "You lost -" + str(bet) + " Euros, because you guessed the dice result is " + dice + ". But that is wrong. The dice result is " + dice_result + ". Your new credit is " + str(money) + " Euros."
#Definieren der Funktion Picking Card. Zwei Spieler ziehen eine Karte aus einem Kartendeck. Die höhere gewinnt. Diese Funktion beinhaltet nicht, die Karten vom Deck abzuziehen, wenn diese gezogen wurde. Ein Kartendeck beim Blackjack besteht aus 52 amerikanischen Karten. Diese setzen sich zusammen aus den vier Farben Herz, Karo, Pik und Kreuz sowie den Kartenwerten 2 3 4 5 6 7 8 9 10 Bube Dame König Ass. Das sind 13 Kartenwerte. Jede Farbe hat 13 Kartenwerte: 4 x 13 = 52.
def picking_card(bet):
global money
deck = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,1 , 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13)
player1 = random.choice(deck)
player2 = random.choice(deck)
if player1 > player2:
money += bet
return "You have chosen a card with the number: " + str(player1) + ". This is" " the higher number. The other Player chose the card with the number: " + str(player2) + ". You won " + str(bet) + " Euros. Your new credit is " + str(money) + " Euros."
elif player1 < player2:
money -= bet
return "You have chosen a card with the number: " + str(player1) + ". This is" " the lower number. The other Player chose the card with the number: " + str(player2) + ". You lost -" + str(bet) + " Euros. Your new credit is " + str(money) + " Euros."
else:
return "It’s a tie! No one wins or loses."
#Definieren der Funktion Roulette. Europäisches Roulette mit 37 Feldern und einer 0. Wenn man "Gerade" und "Ungerade" (wobei dort die 0 nicht mit inbegriffen ist) richtig rät, dann bekommt man seinen Gewinn mit 1:1 (wenn man z.B 17 Euro setzt, bekommt man 34 Euro im Gewinnfall). Wenn man auf eine einzelne Zahl setzt (inklusive 0) und dies richtig ist, dann fällt der Gewinnn 1:35 aus (wenn man z.B 20 Euro setzt, erhält man einen Gewinn von 700 Euro.)
def roulette(bet,ball):
global money
roulette = random.randint(0,36)
print(roulette)
if (ball == "Even") and (roulette % 2 == 0) and (roulette != 0):
money += bet * 2
return "You guessed the field number will be: " + ball + ". That's right! You won " + str(bet * 2) + " Euros. Your new" "credit is " + str(money) + " Euros."
elif (ball == "Odd") and (roulette % 2 != 0) and (roulette != 0):
money += bet * 2
return "You guessed the field number will be: " + ball + ". That's right! You won " + str(bet * 2) + " Euros. Your new" "credit is " + str(money) + " Euros."
elif (ball == str(roulette)):
money += bet * 35
return "You guessed the field number will be: " + ball + ". That's right! You won "+ str(bet * 35) + " Euros. Your new" "credit is " + str(money) + " Euros."
else:
money -= bet
return "You guessed the field number will be: " + ball + ". That's wrong! You lost -" + str(bet) + " Euros. Your new" "credit is " + str(money) + " Euros."
#Call your game of chance functions here
print(flip_coin(11.28,"Tails"))
print()
print()
print(cho_han(50.50,"Even"))
print()
print()
print(picking_card(22.38))
print()
print()
print(roulette(43.00,"Even"))
print()
print()
print(roulette(43.00,"Odd"))
print()
print()
print(roulette(43.00,"0"))
print()
print()
print(roulette(43.00,"37"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment