Answer to Question #51431 in Python for seid

Question #51431
Write a program, to read in all the marks for an exam (these will all be integers and each must be on a new line) and print out the class average, the highest mark and the lowest mark. Your program must be able to handle any number of marks i.e. any size of class – a negative integer will be the last number input (this is not a mark, it is just to let your program know there is no more input). If there are no marks entered (just a negative) then average, minimum and maximum are all N/A (meaning not applicable). Give the average as an integer, truncating any fractional part (e.g. 66.99 given as 66). Your program must start by printing out “Give all the marks, followed by a negative number”, and end by printing average, minimum and maximum exactly as in the example:

Example:
-------------
Give all the marks, followed by a negative number
65
30
45
60
50
-1
class average was 50, lowest mark 30, highest mark 65
1
Expert's answer
2015-03-18T14:11:30-0400
'''Written for Python 2.7.2.'''
print 'Give all the marks, followed by a negative number'
l = []
while True:
try:
n = int(raw_input(''))
except:
continue

if n < 0:
if len(l)==0:
av = 'N/A'
low = 'N/A'
high = 'N/A'
break
else:
av = sum(l)/len(l)
low = min(l)
high = max(l)
break
else:
l.append(n)
continue

print 'class average was {0}, lowest mark {1}, highest mark {2}'.format(av,low,high)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

seid
31.03.15, 09:04

Thanks for the solutions for my questions but unfortunately i can them wing IDE for python

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS