
Taylor W. answered 08/01/23
Tutor
New to Wyzant
Professional Python Developer
import math
def calculate_mean(lst):
if not lst:
return 0
return sum(lst) / len(lst)
def calculate_standard_deviation(lst):
mean = calculate_mean(lst)
variance = sum((x - mean) ** 2 for x in lst) / len(lst)
std_deviation = math.sqrt(variance)
return std_deviation
def main():
# Prompt the user to enter a list of numbers separated by a space
input_list = input("Enter numbers: ").split()
# Convert the input string list to floats
try:
input_list = [float(num) for num in input_list]
except ValueError:
print("Invalid input. Please enter a list of numbers.")
return
# Calculate the mean and standard deviation
mean = calculate_mean(input_list)
std_deviation = calculate_standard_deviation(input_list)
# Display the results
print("The mean is", round(mean, 2))
print("The standard deviation is", round(std_deviation, 5))
if __name__ == "__main__":
main()