python小程序(2)#输入三个整数,将这三个数由小到大输出
思路:
1.先将a,b两个数做比较,并将较大的放在第一的位置,较小的放在第二的位置。
2.再将c分别与第一的数与第二的数作比较,这里分了三种情况:
- c最大,将之前第二大的数放在第三位,之前第一大的数放在第二位,c放在第一位
- c比第一位的小,比第二位的大,将之前第二位的数放在第三位,c放在第二位
- c最小,c放在第三位,其他不变
a=int(input('Please input the first number:'))
b=int(input('Please input the second number:'))
c=int(input('Please input the second number:'))
if a>b:
first=a
second=b
else:
first=b
second=a
if first<c:
third=second
second=first
first=c
elif first>c and c>second:
third=second
second=c
elif c<second:
third=c
print('first number:',third)
print('second number:',second)
print('third number:',first)
本文介绍了一个简单的Python小程序,用于接收用户输入的三个整数,并使用基本的比较逻辑将它们按从小到大的顺序进行排序。通过一系列的条件判断,程序能够正确地确定三个数之间的相对大小并输出排序后的结果。
3830

被折叠的 条评论
为什么被折叠?



