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