Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # ex. 5_1
- # Write a program which repeatedly reads numbers until the user enters “done”.
- # Once “done” is entered, print out the total, count, and average of the numbers.
- # If the user enters anything other than a number, detect their mistake using try and except and print an error message and skip to the next number.
- x=raw_input('Please input number\n')
- while x!='done':
- if x.isdigit()==False:
- x=raw_input('Please give me a real number\n')
- else: x=raw_input('Please input another number \n')
- print 'You\'re done'
- # ex. 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.
- values = [1, 3, 5, 7, 9, 11]
- def min_val(values):
- smallest=None
- for value in values:
- if smallest is None or value<smallest:
- smallest=value
- return smallest
- def max_val(values):
- biggest=None
- for value in values:
- if biggest is None or values>biggest:
- biggest=value
- return biggest
- def return_m_M (values):
- x=min_val(values)
- y=max_val(values)
- print x, y
- return_m_M(values)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement