Lesson 6
Dealing with Sequences of Objects
Chapter 5: Applied problem solving
The smallest number
Now, let us try to apply your new tools to solve more programming problems!
Let us start with something simple to warm up.
Write a function compute_min()
that takes a list of integers as input, and returns the smallest of these integers. Do not use the min()
function for this exercise - try implementing your own as a practice!
Test your function to make sure it behaves correctly for all possible cases you can think of!
Then write a program that reads in integers from the user. The program will stop reading when the user enters q
, and returns the smallest number entered by the user.
Sample run #1
Please enter an integer: 1
Please enter an integer: 24
Please enter an integer: 7
Please enter an integer: 3
Please enter an integer: q
1
Sample run #2
Please enter an integer: 42
Please enter an integer: 0
Please enter an integer: 13
Please enter an integer: -1
Please enter an integer: 68
Please enter an integer: -42
Please enter an integer: q
-42
Sample run #3
Please enter an integer: 31
Please enter an integer: q
31