game = int(input("Math Game (1) or Binary Game (2)? ")) numPrompt = input( "\nHow many questions do you want per game (1 to 10)? ") while True: try: num = int(numPrompt) break except: print("You did not enter a valid number, please try again") numPrompt = input( "\nHow many questions do you want per game (1 to 10)? ") if game == 1: mg.noOfQuestions = num printInstructions(mathInstructions) score += mg.generateQuestions() else: bg.noOfQuestions = num printInstructions(binaryInstructions) score += bg.generateQuestions() print("\nYour current score is %d" % (score)) userChoice = int(input("\nPress enter to continue or -1 to end: ")) updateUserScore(newUser, name, str(score)) except Exception as e: exc_type, exc_obj, exc_tb = sys.exc_info() fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1] print("An unknown error occured. Program will exit.")
game = input('\nMath Game (1) or Binary Game(2)?') #prompt user for number of questions per game numPrompt = input('\nHow many questions do you want per game (1 to 10)?: ') while True: try: num = int(numPrompt) break except: print('You did not enter a valid number.') numPrompt = input('How many questions do you want per game (1 to 10)?') #display relevant questions based on user's selection and update user's score if game == '1': mg.noOfQuestions = num gametasks.printInstructions(mathInstructions) score = score + mg.generateQuestions() else: bg.noOfQuestions = num gametasks.printInstructions(binaryInstructions) score = score + bg.generateQuestions() #display updated score to user print('Your score is ' + str(score)) #prompt user to enter a choice again and use it to update userChoice userChoice = input('If you wish to exit the game, enter -1. Otherwise, press enter to continue: ') #update the user's score after he/she exits the program gametasks.updateUserScore(newUser, userName, str(score))