Python程序最多找到三个数字
在本教程中,我们将编写一个程序,该程序从这三个数字中找出最大数量。我们将有三个数字,我们的目标是从这三个数字中找出最大的数字。
让我们看一些示例测试案例,以更好地理解。
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
请按照以下步骤查找三个数字中的最大数字。
算法
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.
让我们看一下上面算法的代码。
示例
## 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)
输出结果
如果运行上述程序,将得到以下输出。
Maximum is 34
让我们针对不同的测试案例再次执行代码
示例
## 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}")
输出结果
如果运行上述程序,将得到以下输出。
Maximum is 5