Exemple #1
0
            "\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.")
    print("Error: {0} at line {1} in file: {2}".format(e, exc_tb.tb_lineno,
                                                       fname))
            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))

except Exception as e:
    #inform users that an error has occurred and the program will exit
    print('An error has occurred. The program will now exit.')
    print('Error: ', e)
Exemple #3
0
                break
            except:
                print("Invalid entry " + str(numPrompt))
                numPrompt = input("How many questions do you want per game (1 - 10)?")

        # display relevant questions based on user's selection and update user's score
        if (game == '1'):
            mg.noOfQuestions = numInt
            #print(mg.noOfQuestions)
            printInstructions(mathInstructions)
            score += mg.generateQuestions()
        elif (game == '2'):
            bg.noOfQuestions = numInt
            printInstructions(binaryInstructions)
            score += bg.generateQuestions()
        else:
            print("! Invalid game code " + str(game))

        # display updated score to user
        print("New Score (" + userName + ") = " + str(score))

        # prompt user to enter a choice and use it to update userChoice
        prompt = input("Press Enter to continue of enter -1 to exit")
        if (prompt == '-1'):
            userChoice = -1

    # update the user's score after he exits
    updateUserScore(newUser, userName, str(score))

except Exception as e:
    print("Unknown Error, program will exit...error = " + str(e))
            game = input("Enter either 1 for MathGame or 2 for BinaryGame: ")

        numPrompt = input("How many questions do you want per game (1-10)? ")

        while (True):
            try:
                num = int(numPrompt)
                break
            except:
                print("The answer given wasn't an integer")
                numPrompt = input("Enter another answer: ")

        if game == "1":
            mg.noOfQuestions = num
            printInstructions(mathInstructions)
            score += mg.generateQuestions()
        else:
            bg.noOfQuestions = num
            printInstructions(binaryInstructions)
            score += bg.generateQuestions()

        print(score)

        userChoice = input("Press Enter to continue or -1 to exit: ")

    updateUserScore(newUser, userName, score)

except Exception as e:
    print(e)
    print("System Generated Error")
    print("An unknown error has occurred")
Exemple #5
0
            try:
                game = int(input('Math Game (1) or Binary Game (2)?: '))
                if game != 1 and game != 2:
                    game = 0
                    print('Please enter 1 or 2')
            except ValueError:
                print('Please enter 1 or 2')
        numPrompt = input(
            'How many questions do you want per game (1 to 10): ')
        while True:
            try:
                num = int(numPrompt)
                break
            except:
                numPrompt = input('Please enter a number: ')
        if game == 1:
            mg.noOfQuestions = num
            print(mathInstructions)
            score += mg.generateQuestions()
        elif game == 2:
            bg.noOfQuestions = num
            print(binaryInstructions)
            score += bg.generateQuestions()
        userChoice = '-1'
    gametasks.updateUserScore(userName, score, newUser)
    newScore = gametasks.getUserScore(userName)
    print('You answered {} questions correct and your new score is {}!'.format(
        score, newScore))
    input('Press Enter to exit: ')
except:
    print('Error')
Exemple #6
0
    binaryInstructions = '''\nIn this game, you will be given a number in base 10.
  Your task is to convert this number to base 2.
  Each correct answer gives you one mark.
  No mark is deducted for wrong answers\n'''

    #Setting game and user
    bg = BinaryGame(4)
    mg = MathGame(4)

    userName = input('Please enter your name: ')
    curScore = getUserScore(userName)
    newUser = False if curScore != -1 else True

    if newUser == True:
        updateUserScore(newUser, userName)
        curScore = 0

    print('\nWelcome %s, your current score is %d' % (userName, curScore))

    #Main game while loop
    userChoice = 0
    while userChoice != '-1':

        #Select game
        game = input('\nMath Game (1) or Binary Game (2): ')
        while game != '1' and game != '2':
            game = input(
                '\nEnter 1 or 2 please. Math Game (1) or Binary Game (2): ')

        while True: