0

I get this reply after executing check50:

:) professor.py exists
:( Little Professor rejects level of 0
    expected program to reject input, but it did not
:( Little Professor rejects level of 4
    expected program to reject input, but it did not
:( Little Professor rejects level of "one"
    expected program to reject input, but it did not
:( Little Professor accepts valid level
    expected exit code 0, not 1
:| At Level 1, Little Professor generates addition problems using 0–9
    can't check until a frown turns upside down
:| At Level 2, Little Professor generates addition problems using 10–99
    can't check until a frown turns upside down
:| At Level 3, Little Professor generates addition problems using 100–999
    can't check until a frown turns upside down
:| Little Professor generates 10 problems before exiting
    can't check until a frown turns upside down
:| Little Professor displays number of problems correct
    can't check until a frown turns upside down
:| Little Professor displays EEE when answer is incorrect
    can't check until a frown turns upside down
:| Little Professor shows solution after 3 incorrect attempts
    can't check until a frown turns upside down

I have the following code and can't figure out the problem since it works totally fine while testing manually.

import random
import sys


def main():
    generate_integer(generate_level())


def generate_level():
    try:
        while True:
            level = input("Level: ")
            if level in ["1", "2", "3"]:
                return level
            else:
                continue
    except ValueError:
        sys.exit("wrong level")


def generate_integer(level):
    score = 0
    for i in range(10):
        trial = 1
        if level == "1":
            x = random.randint(0, 9)
            y = random.randint(0, 9)
        elif level == "2":
            x = random.randint(10, 99)
            y = random.randint(10, 99)
        else:
            x = random.randint(100, 999)
            y = random.randint(100, 999)

        while True:
            print(f"{x} + {y} = ", end="")
            anwser = input()
            if anwser == str(x + y):
                score = score + 1
                break
            elif anwser != str(x + y) and trial != 3:
                print("EEE")
                trial = trial + 1
            else:
                print("EEE")
                print(f"{x} + {y} = {x + y}")
                break
    print(f"Score: {score}")


if __name__ == "__main__":
    main()

Thank you for any suggestions in advance!

1 Answer 1

2

As per the spec:

Structure your program as follows, wherein get_level prompts......

Program does not have a function named get_level..

1
  • It finally worked thanks! Commented Sep 12, 2023 at 12:52

You must log in to answer this question.

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