Table of Contents

Find the Larger of Two Numbers | Pictoblox

Example Description
This Python program compares two numbers and prints the larger one using if-else statements, the program will output which number is larger

Introduction:

In this Python program, we will compare two numbers and determine the larger of the two. We will use an if-else statement to check if the first number is larger than the second number. If it is, the program will print “first number is larger”. Otherwise, it will print “second number is larger”.

Code:

#Program to find larger of the two numbers
num1 = 5
num2 = 6
if num1 > num2: #Block1
 print("first number is larger") 
 print("Bye")
else: #Block2
 print("second number is larger") 
 print("Bye Bye")

Logic:

  1. We define two variables “num1” and “num2” and assign them the values 5 and 6 respectively.
  2. We use an if-else statement to check if “num1” is greater than “num2”.
  3. If it is, we print “first number is larger” and “Bye”.
  4. If not, we print “second number is larger” and “Bye Bye”.

Output:

>> second number is larger

>> Bye Bye