python3 经典练习题:输入三个数,输出三个数中的最大数

# 第一种写法:
num1 = float(input('请输入第一个数:'))
num2 = float(input('请输入第二个数:'))
num3 = float(input('请输入第三个数:'))
if num1 < num3 and num2 < num3:
    big_num = num3
elif num1 < num2 and num3 < num2:
    big_num = num2
else:
    big_num = num1
print('三个数中最大数为:%s' % big_num)


# 第二种写法(工作量会指数级增加):
n1= int(input('please enter the firest number:'))
n2 = int(input('please enter the second number:'))
n3 = int(input('please enter the third number:'))
max_num = 0

if n1 > n2:
    max_num = n1
    if n1 > n3:
        max_num = n1
    else:
        max_num = n3
else:
    max_num = n2
    if n2 > n3:
        max_num = n2
    else:
        max_num = n3
print('the max_num is:%d'%max_num)


# 第三种写法(最简写法):
num1 = float(input('请输入第一个数:'))
num2 = float(input('请输入第二个数:'))
num3 = float(input('请输入第三个数:'))
max_num = num1        # 先假设num1最大
if max_num < num2:
    max_num = num2
if max_num < num3:
    max_num = num3
print('最大数是:%f' % max_num)
    原文作者:weixin_44119383
    原文地址: https://blog.csdn.net/weixin_44119383/article/details/86710421
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞