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:
- We define two variables “num1” and “num2” and assign them the values 5 and 6 respectively.
- We use an if-else statement to check if “num1” is greater than “num2”.
- If it is, we print “first number is larger” and “Bye”.
- If not, we print “second number is larger” and “Bye Bye”.
Output:
>> second number is larger
>> Bye Bye