I want to make a program that calculates the standard deviation on any amount of input data. To achieve that, the number of input to be accepted has to be infinte and in the process of trying to achieve that, i keep on getting this error.
I tried creating a while loop and setting the condition that if the input is in the class ("", "q", "quit", "end", "stop", "s"), the program should break and if the input is an integer, the program should append the input into the predefined list.
the code I tried is below.
#THE AIM OF THIS CODE IS TO MAKE A PROGRAM THAT CALCULATES THE STANDARD DEVIATION OF A GIVEN SET OF INTEGERS
numbers = [ ]
while True:
value = (input("Enter Number: "))
#Asks for input
if value.lower in ("", "q", "quit", "end", "stop", "s"):
break
#Instructs the program to break if the value of the input is any of these
elif value.isdigit():
numbers.append(int(value))
else:
print("Invalid entry, enter only integers")
print(numbers)
I’ve sorted out the error but now if I input "quit", the program returns the message "Invalid entry, enter only integers" which is the condition for when the input doesn’t follow the former statements.
>Solution :
Your code works for me except when it needs to exit the loop: it won’t even when I pass q or similar.
This is because your code is missing () in order to call lower. It should be
if value.lower() in ("", "q", "quit", "end", "stop", "s")