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)
Numbers and figures are an essential part of our world, necessary for almost everything we do every day. As important…
APPROVED BY CLIENTS
"assignmentexpert.com" is professional group of people in Math subjects! They did assignments in very high level of mathematical modelling in the best quality. Thanks a lot
Comments
Thanks for the solutions for my questions but unfortunately i can them wing IDE for python
Leave a comment