write a Python program to find which numbers greater number in three numbers
Answers
Answer:
# Python program to find the largest number among the three input numbers
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)
The following codes will have to be typed in script mode, saved and then executed.
CODE:
x = int(input("Enter a value:"))
y = int(input("Enter a second value:"))
z = int(input("Enter a third value:"))
if x > y and x > z:
print(x, "is the greater value.")
elif y > x and y > z:
print(y, "is the greater value.")
elif z >x and z > y:
print(z, "is the greater value.")
else:
print("Please enter three distinct values.")
We've made use of the IF-ELIF conditional statement as well as logical operators.
Once the user inputs three values, the system validates with the first condition. If both the conditions are true, it'll run the IF part. If it isn't, it will keep validating with each condition, until it reaches a condition that holds true and will run the required part, ELIF.
The 'and' operator holds TRUE only all the conditions entered is true. If one of the conditions is false, it will hold FALSE.