Exercise 5.2: Write another program that prompts for a list of numbers as
above and at the end prints out both the maximum and minimum of the numbers
instead of the average.
Python for Everybody: Exploring Data Using Python 3
by Charles R. Severance
count = 0
sums = 0
avg = 0
smallest = None
largest = None
while True :
inp_num = input("Enter a number: ")
try :
inp_num = int(inp_num)
count = count + 1
if smallest is None or inp_num < smallest :
smallest = inp_num
if largest is None or inp_num > largest:
largest = inp_num
except :
if inp_num == "done":
print("smallest number: ", smallest)
print("largest number: ", largest)
break
print("invalid input !!!")
continue
sums = sums + inp_num
avg = sums / count
print(sums, count, avg)
quit()
'PYTHON' 카테고리의 다른 글
Answer (5-01) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
---|---|
Answer (4-07) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (4-06) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (3-03) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |
Answer (3-02) for Python for Everybody by Charles R Severance (0) | 2019.09.23 |