Advertisement
Mars83

5-2

Oct 4th, 2011
853
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. #! /usr/bin/env python3.2
  2. # -*- coding: utf-8 -*-
  3.  
  4. # main.py
  5. """ Task: Exercise 5.2
  6.    Write another program that prompts for a list of numbers as above and at
  7.    the end prints out both the maximum and minimum of the numbers instead of
  8.    the average.
  9. """
  10.  
  11. # Main
  12. number = None
  13. numbers = []
  14. min = None
  15. max = None
  16. while number != "done":
  17.     try:
  18.         number = input("Enter a number: ")
  19.         if number == "done":
  20.             break
  21.         try:
  22.             number = float(number)
  23.         except ValueError:
  24.             print("Invalid input")
  25.             continue    # skip code below
  26.     except:
  27.         print("Error")
  28.         continue    # skip code below
  29.     numbers.append(number)  # appends the number at the end of a list 'numbers'
  30.  
  31. # Determine min / max
  32. for num in numbers:
  33.     if min == None or min > num:
  34.         min = num
  35.     if max == None or max < num:
  36.         max = num
  37.  
  38. # Print-out
  39. print("Minimum: " + str(min) + "; Maximum: " + str(max))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement