Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env python3.2
- # -*- coding: utf-8 -*-
- # main.py
- """ Task: 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.
- """
- # Main
- number = None
- numbers = []
- min = None
- max = None
- while number != "done":
- try:
- number = input("Enter a number: ")
- if number == "done":
- break
- try:
- number = float(number)
- except ValueError:
- print("Invalid input")
- continue # skip code below
- except:
- print("Error")
- continue # skip code below
- numbers.append(number) # appends the number at the end of a list 'numbers'
- # Determine min / max
- for num in numbers:
- if min == None or min > num:
- min = num
- if max == None or max < num:
- max = num
- # Print-out
- print("Minimum: " + str(min) + "; Maximum: " + str(max))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement