[Python] Why doesn't my program professor.py pass check50? CS50 Python Problem Set 4 - Little...

Discussão em 'Python' iniciado por Stack, Julho 14, 2025.

  1. Stack

    Stack Membro Participativo

    I tried everything I could but I couldn't seem to find the issue. When I run my program normally, it gives me the correct output for everything. I cannot understand check50's error Here are the specifications required: https://cs50.harvard.edu/python/2022/psets/4/professor/

    import random


    def main():
    level = get_level()
    score = 0
    for i in range(10):
    problem = generate_integer(level)
    list = problem.split("=")
    prob = list[0]
    ans = list[1]
    ans = int(ans)
    answer = input(prob + "= ")
    if answer.isdigit():
    answer = int(answer)
    else:
    print("EEE")
    continue
    if answer != ans:
    print("EEE")
    answer1 = input(prob + "= ")
    answer1 = int(answer1)
    if answer1 == ans:
    score += 1
    continue
    if answer1 != ans:
    print("EEE")
    answer2 = int(input(prob + "= "))
    if answer2 == ans:
    score += 1
    else:
    print(prob + "= " + list[1])
    continue
    else:
    score += 1
    print("Score:", score)


    def get_level():
    while True:
    level = input("Level: ")
    if level.isdigit():
    level = int(level)
    else:
    continue
    if level != 1 and level != 2 and level != 3:
    continue
    else:
    break
    return level


    def generate_integer(level):
    problem = ""
    if level == 1:
    X = random.randint(1, 9)
    Y = random.randint(1, 9)
    elif level == 2:
    X = random.randint(10, 99)
    Y = random.randint(10, 99)
    elif level == 3:
    X = random.randint(100, 999)
    Y = random.randint(100, 999)
    problem = f"{X} + {Y} = {X+Y}"
    return problem

    if __name__ == "__main__":
    main()



    I saw other questions using random.seed(), but here I never used random.seed() [​IMG] [​IMG]

    Continue reading...

Compartilhe esta Página