Skip to main content
2 of 2
edited tags
UpAndAdam
  • 1.7k
  • 1
  • 3
  • 20

CS50P Little Professor error expected "9", not "level: 6 + 6 =..."

When doing check50 I get the error ":( Little Professor displays number of problems correct ". I've found this post where the code works but after comparing it with my own code I still can't find the reason why it won't work. I've changed the def get_level() and def get_integer() after my search but it stil doesn't work. Screenshot of the error.

import random
def main():
    score = count = wrong_count = 0

    level = get_level()

    while True:
        y = generate_integer(level)
        z = generate_integer(level)
        answer = input(f"{y} + {z} = ")
        try:
            if int(answer) == y + z:
                score += 1
                count += 1
            else:
                while True:
                    print("EEE")
                    wrong_count += 1
                    count += 1
                    if count == 10:
                        break
                    if wrong_count == 3:
                        print(f"{y} + {z} = {y+z}")
                        wrong_count = 0
                        break
                    answer = input(f"{y} + {z} = ")
                    if answer == str(y + z):
                        score += 1
                        break
        except ValueError:
            print("EEE")
        if count == 10:
            print(f"Score: {score}")
            break

def get_level():
    while True:
            level = input("level: ")
            if level in ["1", "2", "3"]:
                return level


def generate_integer(level):
    if level == "1":
        return random.randrange(0, 9)
    elif level == "2":
        return random.randrange(10, 99)
    elif level == "3":
        return random.randrange(100, 999)
    else:
        raise ValueError
if __name__ == "__main__":
    main()