0

My program for CS50 works fine when i run it manually, but the Check50 is saying ":( Little Professor generates 10 problems before exiting timed out while waiting for program to exit" Im not sure how to fix this problem since I dont get the same issue when I run it manually.

Code pasted below:

import random
import sys


def main():
    l = int(get_level())
    #problem counter
    problem = 0
    # number of questions incorrect
    incorrect = 0
    while problem < 10:
        x = generate_integer(l)
        y = generate_integer(l)
        tries = 0
        while tries < 3:
            print(x, "+", y, "= ", end="")
            try:
                guess = int(input(""))
            except ValueError:
                print("EEE")
                tries += 1
            #if answer is correct
            if guess == (x + y):
                #finished problem
                problem +=1
                break
            #if answer is incorrect
            else:
                print("EEE")
                tries += 1
        #if user runs out of tries
        if tries == 3:
            print(x, "+", y, "=", end="")
            print(x + y)
            problem += 1
            incorrect += 1
    #once problem counter hits 10 i.e is on the 11th question, should terminate
    if problem ==10:     
        correct = 10 - int(incorrect)
        print("Score: ",correct, sep="")
        sys.exit()


def get_level():
    #loop to obtain level, only accepts 1,2,3
    while True:
        try:
            l = int(input("Input:"))
            if l in (1, 2, 3):
                return l
            else:
                continue
        except ValueError:
            pass


def generate_integer(l):
    if l == 1:
        range_start = 0
        range_end = 9
    if l == 2:
        range_start = 10
        range_end = 99
    if l == 3:
        range_start = 100
        range_end = 999

    return random.randrange(range_start, range_end)


if __name__ == "__main__":
    main()

1 Answer 1

1

Did you ever get a solution to this? Struggling with this problem myself

Edit: I changed random.randrange() to random.randint() and for some reason that fixed it for me. I have absolutely no idea why, it seemed to work exactly the same on my end either way.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .