Last answered:

23 Oct 2021

Posted on:

23 Aug 2021


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

mean = sum(nums) / len(nums)

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)
Posted on:

23 Oct 2021


Your code print 'Enter a number' but there are other problems in it :

  1. what if the first input is a string? ---> your code will exit with error
  2. 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!)image

Submit an answer