learningtoc0d3
learningtoc0d3

Reputation: 49

How do I make all the inputs I recieve go into a data set?

I want to make a program that calculates standard deviation and other statistical functions. However, right now, the best bet I have is to manually type out 10 (sometimes more) variables so I can insert them into formulas so I can get the answer. I just want to be able to type a bunch of numbers and have them go into preassigned data sets and then everything more streamlines. Here is my current code

a1, a2, a3, a4, a5, a6, a7, a8, a9, a10 = input().split() 
mean = (a1 + a2 + a3 + a4 + a5 + a6 + a7 + a8 + a9 + a10)/10
std_dev = (a1-mean)+(a2-mean)...

I haven't finished it yet because I don't want to waste my time doing the code like this if there's a faster function available. I was thinking of doing:

dataset1 = {float(input()), {float(input())}
print(dataset1)

but there's two problems with this. First of all, I don't know how many data points I'll be inserting into the program. With this code, I have to copy {float(input()) and paste that for however many data points I'll have. Also, secondly (and most importantly), this code doesn't work. The code error shows up and it says:

File "..\Playground\", line 2 print(dataset1) ^ SyntaxError: invalid syntax

Upvotes: 1

Views: 31

Answers (1)

askaroni
askaroni

Reputation: 993

import statistics

values = [float(x) for x in input().split()]
mean = statistics.mean(values)

Upvotes: 1

Related Questions