In Python
def main():
c = 10
print("Welcome to Roderick's Chikkin and Gravy")
e = False
while not e:
x = input("Would you like some chikkin?")
if x == "Y" or x == "y":
c = f(c)
else:
e = True
if c == 0:
e = True
print("I hope you enjoyed your chikkin!")
def f(c):
if c > 0:
print("Got you some chikkin! Enjoy")
return c-1
else:
print("No chikkin left. Sorry")
return 0
main()
For practice with lists, create a Python repl that does the
following: A user will type in 10 numbers. It then calculates and
outputs the standard deviation (SD) of those numbers. The formula
to use for the SD is found through the following
mini-algorithm:
1. Find the average of the values.
2. Find the sum of the square of the difference between each item you read in and the average. So, if I only have 3 inputs 1,2,3, the average is 2 so the sum of the square of the differences is: (2-1)^2 + (2-2)^2 + (2- 3)^2 = 2 (in this example).
3. Divide the value in the previous step by 9 (for 10 numbers).
4. Take the square root of the value from the previous step.
If you like the solution please give it a thubs up. And if you have any query please let me know in the comments.
Solution :-
python code :-
lst = []
# number of elemetns as input
n = 10
print("enter the numbers :- ");
for i in range(0, n):
temp = int(input())
lst.append(temp)
# find average for list
mean = sum(lst)/len(lst)
# find variance for list
variance = sum([((x - mean) ** 2) for x in lst])
variance = variance/(n-1)
# take square root of variance for std deviation
stdDev = variance ** 0.5
print("standard deviation = " , stdDev)
Sample input /Output :-
enter the numbers :-
23
45
67
1
34
56
8
97
23
26
standard deviation = 29.00957696271277
Get Answers For Free
Most questions answered within 1 hours.