Last answered:

23 Oct 2021

Posted on:

29 Jul 2021

0

Is there a bug in question 5?

For question 5 the solution code goes like this

user_input = input('Please enter a number type exit to stop:> ')
numbers = []
while user_input.lower() != 'exit':
    while not user_input.isdigit():
        print('That is not a number! Numbers only please:> ')
        user_input = input('Try again:> ')
    numbers.append(int(user_input))
    user_input = input('Please enter next number:> ')
total = 0
for number in numbers:
    total += number

Well, I've ran into some problems where I am done inputting my numbers and want to exit but mistyped exit to something else, it goes into the second while loop and is forced to add another number before I could exit.
Is there any solution for this?

2 answers ( 0 marked as helpful)
Instructor
Posted on:

03 Aug 2021

0

Hi Jirawut!
Great to have you in the course and thanks for reaching out!
Can you please support your question with a screenshot containing the entire troubles you’ve encountered? This can help us assist you better. Thank you.
Looking forward to your answer.
Best,
Ivan

Posted on:

23 Oct 2021

0

Hello, With your solution, once you enter the inner loop you will be stucked here even if you enter 'exit' because you check only if the user_input is digital or not (so 'exit' will be not checked anymore!).
We don't need two loops, one isissufficient.
Note that I didn't use list in my solution (it is not necessary) but you can change it according what you made for the calculation of the mean.Question 5 solution

Submit an answer