Python Programming Examples Tutorial Index

Python Number Programs

This Python example code demonstrates a simple Python program to find the greatest of three numbers using If and print the output to the screen. The primary purpose of this Python program is to explain to beginners how decision-making statements work.



Program:

#Variable definition and assignment
num1 = 25
num2 = 30
num3 = 20

#Remove comments from the bottom lines to take input from the user
#num1 = float(input("Enter first number:"))
#num2 = float(input("Enter second number:"))
#num3 = float(input("Enter third number:"))

if (num1 >= num2) and (num1 >= num3):
   largest = num1
elif (num2 >= num1) and (num2 >= num3):
   largest = num2
else:
   largest = num3

#Print the output
print("The largest number is", largest)

Program Output:

The largest number is 30


Found This Page Useful? Share It!
Get the Latest Tutorials and Updates
Join us on Telegram