Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*Spoiler* CS50P Problem Set 4 - Little Professor - Check 50 Gives Green Smilies for Correct Range of Problems and Incorrect Range of Problems #245

Open
gtrdn77 opened this issue Jun 10, 2024 · 0 comments

Comments

@gtrdn77
Copy link

gtrdn77 commented Jun 10, 2024

Hi,
When running my code for the Little Professor problem through check50, I receive all green smilies for code that outputs 10 problems and code that outputs 9 problems by changing the "while questions < 10" to "<9" and "if questions == 10" to "==9" in the code below.

After reviewing my code, I'm still not sure whether my code has an error or check50 is mistakenly suggesting the code that outputs 9 problems is correct. Any help with this would be appreciated! SPOILER

import random
import sys

def main():
    questions = 0
    incorrect_answers = 0
    while True:
        try:
            user_level = get_level()
            if user_level == ValueError:
                pass
            else:
                while questions < 10:
                    attempts = 0
                    questions += 1
                    generated_ints = generate_integer(user_level)
                    x = generated_ints[0]#x is first element of tuple
                    y = generated_ints[1]#y is second element of tuple
                    while attempts <= 2:
                        user_input = int(input(f"{x} + {y} ="))
                        correct_answer = x + y
                        if user_input != correct_answer and attempts == 2:
                            incorrect_answers += 1
                            print(f"Correct Anwer: {correct_answer}")
                            break
                        elif user_input != correct_answer:
                            attempts += 1
                            print("EEE")
                        else:
                            break
                if questions == 10:
                    answered_correctly = 10 - int(incorrect_answers)
                    return print(answered_correctly)
        except EOFError:
            sys.exit("\nGoodbye.")

def get_level():
    while True:
        try:
            level = int(input("Level: "))
            if level not in {1,2,3}:
                pass
            else:
                return level
        except ValueError:
            pass

def generate_integer(level):#generate_integer returns a randomly generated non-negative integer with level digits
#or raises a ValueError if level is not 1, 2, or 3:
    if level not in {1,2,3}:
        return ValueError
    elif level == 1:
        x = random.randint(0,9)
        y = random.randint(0,9)
        return x, y
    elif level == 2:
        x = random.randint(10,99)
        y = random.randint(10,99)
        return x, y
    #elif level == "3":
    else:
        x = random.randint(100,999)
        y = random.randint(100,999)
        return x, y

def final_score(wrong_answers):
    answered_correctly = 10 - int(wrong_answers)
    print(f"Score: {answered_correctly}/10")

if __name__ == "__main__":
    main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant