Resolved: code for question 5 . My code does not print 'ENTER A NUMBER'
user_input =input('Enter a number \n')
nums = []
while user_input != 'stop' and user_input.isdigit():
user_input =input('Enter a number \n')
nums.append(int(user_input))
mean = sum(nums) / len(nums)
print(mean)
Can you please tell me what's wrong with my code ?
the code does not print 'Enter a number'
1 answers ( 1 marked as helpful)
Hello,
Your code print 'Enter a number' but there are other problems in it :
- what if the first input is a string? ---> your code will exit with error
- Inside your loop, you ask user to enter a number and then you directly convert it to integer and append it to the list without
checking if it is valid input or not ---> so here if you enter a string, your program will exit with error
===> So here you should inverse the order of your instructions inside the loop
... there is other problems, you should think about all cases and take and be careful to the order of instructions in your code.
I will attach here my solution, you can check it (note that i did not use list, but you modify it and add list!)