Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # P2PU - Python Programming 101 - Chapter 6 - Flow Control
- # Python for Informatics - Chapter 5 - Iteration
- print '\n# Exercise 5.1\n'
- count = 0
- total = 0
- average = 0
- while True:
- number = raw_input('Enter a number: ')
- if number == 'done' : break;
- try:
- number = float(number)
- count = count + 1
- total = total + number
- except:
- print "Error, please enter a number, or 'done' to finish"
- print 'Total =', total
- print 'Count =', count
- if count > 0 : average = total/count
- print 'Average =', average
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement