-
-
Save codecademydev/d7c04cc8d92d4c6a2ac52b9376240bcc 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 | |
def bet_check(pyt_coin, user_coin, user_bet, user_balance): | |
if (pyt_coin == 1 and user_coin == "heads") or (pyt_coin == 0 and user_coin == "tails"): | |
user_balance = user_balance + user_bet | |
print("You won! Your current balance is {}\n".format(user_balance)) | |
return user_balance | |
else: | |
user_balance = user_balance - user_bet | |
print("You lost! Your current balance is {}\n".format(user_balance)) | |
return user_balance | |
oyun = True | |
balance = 100 | |
print("Let's play heads and tails.\n") | |
while oyun: | |
if balance >0: | |
coin = random.randint(0,1) | |
choice = str(input("What's your choice? Heads? Or Tails?")).lower() | |
bet = int(input("What's your bet amount?")) | |
if bet > balance: | |
print ("You don't have that much funds! Your current balance is {}\n".format(balance)) | |
else: | |
balance = bet_check(coin, choice, bet, balance) | |
if balance > 0: | |
game_continue = str(input("Would you like to play again? Y / N?")).lower() | |
if game_continue == "n": | |
print("Thanks for playing!") | |
oyun = False | |
else: | |
print("Let's continue!\n") | |
# else: | |
else: | |
print("Game Over") | |
oyun = False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment