Jan-20-2018, 07:00 PM
I ran into some issues here, when i typed 'back' to return to the main menu of my program it reset my credits. it does this every time and i can't seem to figure out why. would anyone be able to help me with this? thanks!
#Final Project # 1/17/2018 #This program is an arcade, with a credit system and 3 different gamemodes #--------------------------------------------------------------------- def ws(): print(" ") import random import time credits = 10000 #Currency in the game deposit = 0 def coinflip(credits,deposit): print("Welcome to CoinFlip!") print("================================") print("Credits:", credits) print("================================") print("Winnings Info") print("================================") print("Picking the correct side will grant you double the credits") ws() ws() guess = input("heads or tails? or type 'back' to go to the main menu") #user inputs heads or tails, if they type back they will return to main menu if guess == "back": start() deposit = float(input("How much would you like to bet?")) #user picks his bet ammount, and that ammount is removed from his balance c = ["heads", "tails"] coin = random.choice(c) credits -= deposit def flip(): print("Flipping....") time.sleep(1.5) print("The coin lands on", coin) ws() if coin == "heads" and guess == "heads": flip() credits += deposit*2 print("You Guessed Right!") time.sleep(1.5) print("You Earned", deposit*2, "Credits") time.sleep(1) print("Your Balance is now", credits, "Credits") time.sleep(3) ws() ws() ws() coinflip(credits, deposit) elif coin == "tails" and guess == "tails": flip() credits += deposit*2 print("You Guessed Right!") time.sleep(1.5) print("You Earned", deposit*2, "Credits") time.sleep(1) print("Your Balance is now", credits, "Credits") ws() ws() ws() coinflip(credits, deposit) else: flip() print("Sadly, you lost!") print("You lost", deposit, "Credits") print("Your balance is now", credits, "credits") ws() ws() ws() coinflip(credits, deposit) def RPS(credits, deposit): ws() ws() print("Welcome to Rock, Paper, Scissors") print("========================================") print("Credits:", credits) print("========================================") print("Winnings Info") print("========================================") print("You recieve double your money for winning RPS") print("========================================") ws() ws() o = ["rock", "paper", "scissors"] comppick = random.choice(o) player = input("rock, paper, scissors? Or Type 'back' to go to the main menu") if player == "back": start() deposit = float(input("How much would you like to bet?")) player = player.lower() credits -= deposit def throw(): print("Rock") time.sleep(0.6) print("Paper") time.sleep(0.6) print("Scissors") time.sleep(0.6) print("Shoot!") ws() if player == comppick: throw() credits += deposit print("You Chose", player) print("The Computer Chose", comppick) print("Its a tie!") time.sleep(3) RPS(credits, deposit) elif player == "rock" and comppick == "paper": throw() print("You Chose", player) print("The Computer Chose", comppick) print("You Lost!") time.sleep(3) RPS(credits, deposit) elif player == "rock" and comppick == "scissors": throw() credits += deposit * 2 print("You Chose", player) print("The Computer Chose", comppick) print("You Win!") RPS(credits, deposit) elif player == "paper" and comppick == "rock": throw() credits += deposit * 2 print("You Chose", player) print("The Computer Chose", comppick) print("You Win!") RPS(credits, deposit) elif player == "paper" and comppick == "scissors": throw() print("You Chose", player) print("The Computer Chose", comppick) print("You Lost!") time.sleep(3) RPS(credits, deposit) elif player == "scissors" and comppick == "rock": throw() print("You Chose", player) print("The Computer Chose", comppick) print("You Lost!") time.sleep(3) RPS(credits, deposit) elif player == "scissors" and comppick == "paper": throw() credits += deposit * 2 print("You Chose", player) print("The Computer Chose", comppick) print("You Win!") RPS(credits, deposit) def roulette(credits,deposit): print("Roulette") print("===============") print("Credits:", credits) print("===============") print("Winnings Info") print("===============") print("If you land on odd or even you get 2x your credits!") print("If you land on your specific number you get 28x your money") ws() ws() num = random.randint(0,36) def roll(): ws() print("Spinning...") time.sleep(1.5) print("It has passed", random.randint(0, 36)) #displays to the user what the correct number is time.sleep(1.5) print("Almost lands on", random.randint(0, 36)) time.sleep(1.6) print("It landed on", num) ws() ws() bet = input("Type 'odd', 'even' or 'specific' to pick a certain number. Or type 'back' to return to the menu.") if bet == "back": start() deposit = float(input("Type in how much you want to bet: ")) credits -= deposit if bet == "specific": bet = input("Choose a number between 0 and 36") ws() if bet == num: # if bet number is = to what is rolled you win 28x your money credits += deposit *28 print("Wow! You won! The number was", num) print("You receive", int(deposit)*28, "credits!") print("Your balance is now", credits, "credits") time.sleep(2) ws() roulette(credits,deposit) if num % 2 == 0 and bet == "even": #If the number is even and you pick even you win roll() credits += deposit * 2 print("Wow! You won! It was an even number!") print("You receive", int(deposit)*2, "credits!") print("Your balance is now", credits, "credits") time.sleep(2) ws() roulette(credits,deposit) elif num % 2 != 0 and bet == "odd": roll() credits += deposit * 2 #If the number is odd and you pick odd you win print("Wow! You won! It was an odd number!") print("You receive", int(deposit)*2, "credits!") print("Your balance is now", credits, "credits") time.sleep(2) ws() roulette(credits,deposit) else: #if the if statements above were not correct then you lost roll() print("Sadly, you lost!") print("You lost", deposit, "Credits") print("Your balance is now", credits, "credits") time.sleep(2) ws() roulette(credits,deposit) def start(): print("THE ARCADE") print("==============================") print("Credits:", credits) print("==============================") print("Gamemodes") print("==============================") print("coinflip") ws() print("rps") ws() print("roulette") print("==============================") ws() gamemode = input("Enter Desired Gamemode: ") if gamemode == "coinflip": print("You Picked CoinFlip!") ws() ws() ws() coinflip(credits, deposit) if gamemode == "rps": print("You Picked RPS") ws() ws() ws() RPS(credits,deposit) if gamemode == "roulette": print("You Picked Roulette") ws() ws() ws() roulette(credits,deposit) start()