a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
if a >= b and a >= c:
print("The largest number is:", a)
elif b >= a and b >= c:
print("The largest number is:", b)
else:
print("The largest number is:", c)
#source code --> clcoding.com
Code Explanation:
Taking Input from the User
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
c = int(input("Enter third number: "))
The program asks the user to enter three numbers one by one.
Since input() takes values as strings, we use int() to convert them into integers.
The numbers are stored in variables:
a → First number
b → Second number
c → Third number
Checking if a is the Largest Number
if a >= b and a >= c:
print("The largest number is:", a)
This if condition checks whether a is greater than or equal to both b and c.
If true, a is the largest number, so it prints:
The largest number is: a
Checking if b is the Largest Number
elif b >= a and b >= c:
print("The largest number is:", b)
If the first condition is false, the program checks if b is greater than or equal to both a and c.
If true, b is the largest number, so it prints:
The largest number is: b
If a and b are NOT the Largest, c Must Be the Largest
else:
print("The largest number is:", c)
If neither a nor b is the largest, c must be the largest.
The program prints:
The largest number is: c
0 Comments:
Post a Comment