online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code   
Language
# Name: Nathan Bickus and John Hofbauer # Project: HackPSU Overall - Tech(3) # Project Name: Random Number Gamble Simulator import random print('This program allows users to gamble and guess the random number. Every user begins with $1000.\n') print('Rewards:\nGame1: Win (amount betted * 1)\nGame2: Win (amount betted * 2)\nGame3: Win (amount betted * 3)\nGame4: Win (amount betted * 4)\n') ############################ John Hofbauer worked on the functions getBalance, SaveBalance, and GambleAmount ############################## def getBalance(): try: userFile = open("Balance.txt", "r") userBalance = userFile.readlines() userFile.close() return int(userBalance[0]) except: userFile = open("Balance.txt", "w") userFile.write(str(int(1000))) userFile.close() return int(1000) def SaveBalance(balance): totalBalance = int(getBalance()) + balance userFile = open("Balance.txt", "w") # Opens file and if there is not one, then it creates one. userFile.write(str(totalBalance)) # Writes the users' balance in the file. userFile.close() def GambleAmount(): print("Your balance is: " + str(getBalance())) gambleAmount = int(input('How much would you like to gamble: ')) while (gambleAmount > int(getBalance())): gambleAmount = input("Please type an amount less then " + str(getBalance())+ ': ' ) return int(gambleAmount) ####################################### Nathan Bickus worked on everything below ############################################ def gamble(): print('Answer 1 for game 1, answer 2 for game 2, answer 3 for game 3, or answer 4 for game 4\n') game_choice = int(input('Please enter a number to choose which game you would like to play: ')) gambleAmount = GambleAmount() if game_choice == 1: random_num = random.randint(1,10) try: user_choice = int(input('Please guess a number between 1-10: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') except: user_choice = int(input('Please enter a whole number between 1-10: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') while user_choice > 10 or user_choice < 1: user_choice = int(input('Please enter a number between 1-10: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') if user_choice == random_num: SaveBalance(gambleAmount * game_choice) return 'Congrats you have won! The correct number was: ' + str(random_num) if user_choice != random_num: SaveBalance(gambleAmount * -1) return 'Sorry you have lost, the correct number was: ' + str(random_num) elif game_choice == 2: random_num = random.randint(1,100) try: user_choice = int(input('Please guess a number between 1-100: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') except: user_choice = int(input('Please enter a whole number between 1-100: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') while user_choice > 100 or user_choice < 1: user_choice = int(input('Please enter a number between 1-100: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') if user_choice == random_num: SaveBalance(gambleAmount * game_choice) return 'Congrats you have won! The correct number was: ' + str(random_num) if user_choice != random_num: SaveBalance(gambleAmount * -1) return 'Sorry you have lost, the correct number was: ' + str(random_num) elif game_choice == 3: random_num = random.randint(1,1000) try: user_choice = int(input('Please guess a number between 1-1000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') except: user_choice = int(input('Please enter a whole number between 1-1000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') while user_choice > 1000 or user_choice < 1: user_choice = int(input('Please enter a number between 1-1000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') if user_choice == random_num: SaveBalance(gambleAmount * game_choice) return 'Congrats you have won! The correct number was: ' + str(random_num) if user_choice != random_num: SaveBalance(gambleAmount * -1) return 'Sorry you have lost, the correct number was: ' + str(random_num) elif game_choice == 4: random_num = random.randint(1,10000) try: user_choice = int(input('Please guess a number between 1-10000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') except: user_choice = int(input('Please enter a whole number between 1-10000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') while user_choice > 10000 or user_choice < 1: user_choice = int(input('Please enter a number between 1-10000: ')) print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~') if user_choice == random_num: SaveBalance(gambleAmount * game_choice) return 'Congrats you have won! The correct number was: ' + str(random_num) if user_choice != random_num: SaveBalance(gambleAmount * -1) return 'Sorry you have lost, the correct number was: ' + str(random_num) question = 'Y' while question == 'Y': temp = gamble() print(temp) print('Your new balance is: ' + str(getBalance())) question = input('Do you want to play again? Enter Y/N: ') print('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~')

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue