In this tutorial, we are going to write a program which finds the max amount from the three figures. We will have three number, and our goal is to find out the maximum number from those three numbers.
Let's see some sample test cases for better understanding.
Input: a, b, c = 2, 34, 4 Output: 34
Input: a, b, c = 25, 3, 12 Output: 25
Input: a, b, c = 5, 5, 5 Output: 5
Follow the below steps to find out the max number among three numbers.
Algorithm
1. Initialise three numbers a, b, c. 2. If a is higher than b and c then, print a. 3. Else if b is greater than c and a then, print b. 4. Else if c is greater than a and b then, print c. 5. Else print any number.
Let's see the code for the above algorithm.
Example
## initializing three numbers
a, b, c = 2, 34, 4
## writing conditions to find out max number
## condition for a
if a > b and a > c:
## printing a
print(f"Maximum is {a}")
## condition for b
elif b > c and b > a:
## printing b
print(f"Maximum is {b}")
## condition for c
elif c > a and c > b:
## printing
print(f"Maximum is {c}")
## equality case
else:
## printing any number among three
print(a)Output
If you run the above program, you will get the following output.
Maximum is 34
Let's execute the code once again for different test case
Example
## initializing three numbers
a, b, c = 5, 5, 5
## writing conditions to find out max number
## condition for a
if a > b and a > c:
## printing a
print(f"Maximum is {a}")
## condition for b
elif b > c and b > a:
## printing b
print(f"Maximum is {b}")
## condition for c
elif c > a and c > b:
## printing
print(f"Maximum is {c}")
## equality case
else:
## printing any number among three
print(f"Maximum is {a}")Output
If you run the above program, you will get the following output.
Maximum is 5
Conclusion
If you have any doubts regarding the tutorial, mention them in the comment section.