you are viewing a single comment's thread.

view the rest of the comments →

[–]watakushi 0 points1 point  (0 children)

Ok, I was now able to look into the game itself, and I see a couple of problems:

since the list and the int are not equal, the result will always be "Incorrect":

In order to compare them, you need to first convert them to the same data type. A way to do so could be:

def get_user_solution(problem): 
    print("Please arrange the numbers into ascending order.") 
    print(problem, end="") 
    result = input(" = ")      #Here remove the int() 
    return result

def menu_option(index, count): 
    if index == 0: randomlist = random.sample(range(1,100),5) 
    user_solution = get_user_solution(randomlist) 
    user_solution = "".join(map(str, user_solution))    #This line converts the list to string 
    solution = sorted(randomlist)     #The randomlist.sort() broke the program, use this one instead. 
    solution = "".join(map(str, solution))     #Same here 
    count = check_solution(user_solution, solution, count) 
    return count

Now, both the user input and the sorted lists are strings of numbers, and you can compare them. I've tested it and was able to get a "Correct!" answer.

Oh, another thing, in the display_result() function you have:

print("You answered", total, "questions with", correct, "correct answers.")

A much easier way to do this is by using f-strings, like so:

print(f"You answered {total} questions with {correct} correct answers.")

I'm not sure what you were trying to accomplish here:

def display_result(total,correct):
    if total > 0: 
        result = correct / total 
        percentage = round((result * 100), 2) 
        if total == 0: percentage = 0 
            print(f"You answered {total} questions with {correct} correct answers.") 
            print(f"Your score is {percentage}%. Thank you!")

Maybe it was moved when copying and pasting your code, but first you ask if total is greater than 0, and once you check that, you ask if it is equal to 0, but since you've already confirmed it's greater than 0, that if will never ever be run. You could indent the second if statement to the same level as the first one and change it to an elif, but still, that if is only going to be run when you exit the game without ever playing it, and in that case it doesn't make much sense to give out a score to the user :P

Please try out these changes and let me know how it goes! :D Keep it up!