1

I've made some corrections, the answers for CHECK 50 are the same though. I'm not getting it, the workability of the code is fine (working as expected, even when testing by 'How to Test' section). I really do need some light in here.

(Original post + (NEW) code): I know there are many questions in here with similar problems. But I want to understand what it's wrong with my coding as I've been trying many different approaches and nothing seems to solve it.

The thing is, I've had "correct" output as follows:

    Level: 0
    Level: 4
    Level: one
    Level: ,
    Level: 1
    0 + 8 = 1
    EEE
    0 + 8 = 1
    EEE
    0 + 8 = 1
    EEE
    0 + 8 = 8
    5 + 5 = 1
    EEE
    5 + 5 = 10
    6 + 7 = 13
    3 + 0 = 3
    8 + 0 = 8
    2 + 4 = 6
    4 + 0 = 4
    4 + 1 = 5
    3 + 4 = 7
    1 + 1 = 2
    Score: 8

Still, it returns the following result from "Check 50":

    :) 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

My (NEW) code is as follows:

    import random

    def main():
        level = int(get_level("Level: "))
        score = 0

        for i in range(10):
            error = 1
            x, y = generate_integer(level)
            z = x + y
            while True:
                print(f"{x} + {y} = ", end="")
                answer = input()
                if answer == str(z):
                    score += 1
                    break
                elif answer != str(z) and error < 3:
                    print("EEE")
                    error += 1
                    continue
                else:
                    print("EEE")
                    print(f"{x} + {y} = {z}")
                    break

        print(f"Score: {score}")


    def get_level(n):
        while True:
            level = input(n)
            if level not in ['1', '2', '3']:
                continue
            return level

    def generate_integer(l):
        if l == 1:
            x = random.randint(0, 9)
            y = random.randint(0, 9)
        elif l == 2:
            x = random.randint(10, 99)
            y = random.randint(10, 99)
        elif l == 3:
            x = random.randint(100, 999)
            y = random.randint(100, 999)
        return (x, y)

    if __name__ == "__main__":
        main()

1 Answer 1

3

There is a requirement "hidden" in the How to Test section. Under the 3rd bullet it says (in part):

  • Your program should output 10 distinct problems before printing...

A review of your code shows you don't check for distinct problems. In other words, your generator may prompt with 1 + 4 = then later with 1 + 4 = again. (4 + 1 = would be different.) You may generate 10 distinct problems when you run your tests manually. Run it enough times and you should see a problem repeated (especially for Level=1.)

Good luck.

5
  • That's great, thank you very much. I haven't seen that. I'll check that and see what I can do. Commented Nov 26, 2022 at 14:57
  • I've got what you suggested, the problem is on the 'get_level()', though. The Check50 asks for 'Reject 0, 4, -1' and accepts only 'Valid' input, things my code is accepting though. The problem is something I'm not getting in this particular Function, I believe. Commented Nov 27, 2022 at 11:09
  • Hmmm...when I test, input of 0, 4 and 'one' are rejected and I am re-prompted. There's something check50 doesn't like...but I can't figure out what it is. :-( Other things I noticed: generate_integer() doesn't raise a ValueError if the input isn't 1,2, or 3. Also, your Level 1 problems sometimes have 0 as a value. Finally, it's still possible to generate duplicate problems.
    – kcw78
    Commented Nov 27, 2022 at 18:00
  • I figured it out....check50 expects you to use a try:/except: block to test the input; if statements are not sufficient. Convert your logic to use try:/except: (we learned previously) and you should pass the first 4 tests.
    – kcw78
    Commented Nov 27, 2022 at 18:06
  • Have you been able to solve the problem finally? I have literally the same problem.
    – Leny1111
    Commented Dec 30, 2022 at 19:19

You must log in to answer this question.

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