Lesson 3
Discovering your Paths
Chapter 4: Applying your knowledge
The bigger number
As a warm-up, we will start with an easy challenge.
Write a Python program that reads in two integers from the user, and prints out the number that is larger. For simplicity, you can assume that the user is well-behaved and will always enter an integer. 👼🏼
You will only need everything you have learnt in Lesson 2 (variables, literals, assignment, etc.) and if
/if-else
/if-elif-else
statements to solve this challenge.
Do not use any Python convenience functions like min()
or max()
for this question. That will be too easy!
You can obviously use functions like input()
, int()
and print()
.
This exercise will help develop your critical thinking skills, and help you understand programming at a lower level.
Below are some example runs. Make sure that your code produces the correct answer for all of them.
Also remember that passing all these tests does not mean that your code is 100% correct. Foresee any other possible difficult cases and make sure the program works for these too. For example, what if the user enters two negative numbers?
Sample run #1
Please enter the first integer: 2
Please enter the second integer: 12
12
Sample run #2
Please enter the first integer: 356
Please enter the second integer: 123
356
Sample run #3
Please enter the first integer: 70053
Please enter the second integer: 70053
70053
Sample run #4
Please enter the first integer: -56
Please enter the second integer: 56
56
Sample run #5
Please enter the first integer: 0
Please enter the second integer: -234
0