0

When I run locally the program behaves as I think it should. But when I run it through check50 it fails saying that I dont reject inputs that I should reject.

import random

def main():
    while True:
        try:
            level = int(input("Level: "))
        except ValueError:
            continue

        if get_level(level):
            generate_integer(level)
            break

def get_level(l):

    level_list = [1, 2, 3]

    if l in level_list:
        return True
    else:
        return False


def generate_integer(level):
    correct = 0
    x = 0

    while x < 10:
        tries = 1

        if level == 1:
            num_1 = random.randint(1, 9)
            num_2 = random.randint(1, 9)

            while tries <= 3:
                try:
                    ans = int(input(f"{num_1} + {num_2} = "))

                    if ans == num_1 + num_2:
                        correct += 1
                        x += 1
                        break
                    else:
                        print("EEE")
                        tries += 1

                        if tries == 4:
                            print(f"{num_1} + {num_2} = {num_1 + num_2}")
                            x += 1
                            break

                except ValueError:
                    tries += 1

                    if tries == 4:
                       print(f"{num_1} + {num_2} = {num_1 + num_2}")
                       x +=1
                       break
                    else:
                        print ("EEE")

        elif level == 2:
            num_1 = random.randint(10, 99)
            num_2 = random.randint(10, 99)

            while tries <= 3:
                try:
                    ans = int(input(f"{num_1} + {num_2} = "))

                    if ans == num_1 + num_2:
                        correct += 1
                        x += 1
                        break
                    else:
                        print("EEE")
                        tries += 1

                        if tries == 4:
                            print(f"{num_1} + {num_2} = {num_1 + num_2}")
                            x += 1
                            break

                except ValueError:
                    tries += 1

                    if tries == 4:
                       print(f"{num_1} + {num_2} = {num_1 + num_2}")
                       x +=1
                       break
                    else:
                        print ("EEE")

        elif level == 3:
            num_1 = random.randint(100, 999)
            num_2 = random.randint(100, 999)

            while tries <= 3:
                try:
                    ans = int(input(f"{num_1} + {num_2} = "))

                    if ans == num_1 + num_2:
                        correct += 1
                        x += 1
                        break
                    else:
                        print("EEE")
                        tries += 1

                        if tries == 4:
                            print(f"{num_1} + {num_2} = {num_1 + num_2}")
                            x += 1
                            break

                except ValueError:

                    tries += 1

                    if tries == 4:
                       print(f"{num_1} + {num_2} = {num_1 + num_2}")
                       x +=1
                       break
                    else:
                        print ("EEE")

    print (f"Score: {correct}")




if __name__ == "__main__":
    main()

1 Answer 1

0

The program is not structured as specified

Structure your program as follows, wherein get_level prompts (and, if need be, re-prompts) the user for a level and returns 1, 2, or 3, and generate_integer returns a randomly generated non-negative integer with level digits or raises a ValueError if level is not 1, 2, or 3:

get_level does not take an argument. get_integer "returns a....integer"

You must log in to answer this question.

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