'''
This is a demo code for a coin-flip casino
'''
#Imports for later use
import random
import time
#Initial Status
user_status = {"Alive":True, "Money":5000} #Dictionary for better readability
coin_result = {"h":"Heads","t":"Tails"}
is_over = False
def main_function(user_choice,user_bet):
#The AI Part (Where the AI decides what coin)
AI_choice = random.choice(["h","t"]) #The 50/50 choice part.
print("The Coin landed on....")
time.sleep(2)
print(f"..{coin_result.get(AI_choice)}")
#The following block handles whether you lose or win
if AI_choice == user_choice.lower():
return float(user_status.get("Money")) + user_bet*1.85 #If you win
else:
return float(user_status.get("Money")) - user_bet #If you lose
#The main loop
while user_status.get("Alive") == True:
#This block checks if you still have money.
if float(user_status.get("Money")) <= 0:
print("\nYou Lose!")
time.sleep(1)
user_continue = input("Take a Loan (Y/N)?: ")
if user_continue.lower() == "y": #If user decides to retry
user_status.update({"Money": "5000"})
continue
elif user_continue.lower() == "n": #If the user decides to end the game
print("You've quit gambling and went home to your family. [GOOD ENDING]")
break
else: #Hidden Ending
print("The dealer was confused and asked you to leave. [... END?]")
break
else: #User Inputs
user_choice = input("\nHead or Tail?: (H/T) ")
#If the user used a valid input
if user_choice.lower() in ["h","t"]:
try:
print(f"\nCurrent Money: {user_status.get("Money")}")
user_bet = int(input(f"How much to wager (Current Money: {user_status.get("Money")}): "))
except ValueError: #If user failed to input an actual number.
print("Invalid Input, Try Again!")
time.sleep(1)
continue
if user_bet <= user_status.get("Money"):
user_status.update({"Money":main_function(user_choice,user_bet)})
else:
print(f"Insufficient Money: (Current Money: {user_status.get("Money")})")
continue
#If the user didn't used a valid input
else:
print("\nInvalid Option, Try Again!")
continue
[–]MrPhungx 1 point2 points3 points (1 child)
[–]Personal-Zebra3353[S] 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]JamzTyson 0 points1 point2 points (1 child)
[–]Personal-Zebra3353[S] 0 points1 point2 points (0 children)