#Q2
quiz_marks = []
total = 0
mark = float(input("Enter a quiz mark (negative number to stop): "))
while mark >= 0:
quiz_marks.append(mark)
total += mark
mark = float(input("Enter a quiz mark (negative number to stop): "))
n = len(quiz_marks)
mean = total / n
variance = 0
for mark in quiz_marks:
variance += (mark - mean) ** 2
variance /= n
print("Mean:", mean)
print("Variance:", variance)
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter