Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

SyntaxError in python program meant to calculate standard deviation

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

#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")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading