python多种语法实现依次接收用户输入的3个数,排序后打印

这篇博客介绍了五种不同的Python语法来接收用户输入的三个数,并进行排序。方法包括转换为int后使用分支结构,利用列表,max函数,sort方法以及冒泡排序法,最后展示了排序后的结果。
摘要由CSDN通过智能技术生成

1.转换int后,判断大小排序,使用分支结构

a = int(input(“first number>>>”))
b = int(input(“second number>>>”))
c = int(input(“third number>>>”))

if a > b:
if b > c:
        print(a,b,c)
elif a > c:
    print(a,c,b)
else:
    print(c,a,b)
else:             #a <= b
if a > c:
    print(b,a,c)
elif b > c:     #a <= c
    print(b,c,a)
else:
    print(c,b,a)

2.列表

nums = []
for i in range(3):
nums.append(int(input(‘{}:’.format(i))))

if nums[0] > nums[1]:
if nums[0] > nums[2]:
l1 = nums[0]
if nums[1] > nums[2]:
    l2 = nums[1]
    l3 = nums[2]
else:
    l2 = nums[2]
    l3 = nums[1]
else:
    l1 = nums[2]
    l2 = nums[0]
l3 = nums[1]
else:  #nums[0] <= nums[1]
if nums[0] < nums[2]:
l3 = nums[0]
if nums[1] > nums[2]:
    l1 = nums[1]
    l2 = nums[2]
else:
    l1 =
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值