1 min read
Create a Python program to find the largest among the three given numbers.
In this article, we will show you two methods to address this same problem one being the conventional way and the other being the Pythonic way.
To understand the program you need to have an understanding of following Python concept.
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 largest number is",largest)
Enter first number: 1
Enter second number: 2
Enter third number: 3
The largest number is 3.0
num1 = float(input("Enter first number: "))
num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
my_list = [num1, num2, num3]
Largest = max(my_list)
print("The Largest number is", Largest)
Enter first number: 1
Enter second number: 2
Enter third number: 3
The largest number is 3.0
In this approach, we are making a list of all the inputs and using the max()
method which returns the item with the highest value in the list.
Latest from djangocentral
2 min read
2 min read