用python制作输入四个整数要求按从大到小顺序输出用到if
时间: 2023-12-15 14:03:25 浏览: 64
语句该怎么写?
可以使用以下代码:
a = int(input("请输入第一个整数:"))
b = int(input("请输入第二个整数:"))
c = int(input("请输入第三个整数:"))
d = int(input("请输入第四个整数:"))
if a >= b and a >= c and a >= d:
max_num = a
if b >= c and b >= d:
mid1_num = b
if c >= d:
mid2_num = c
min_num = d
else:
mid2_num = d
min_num = c
elif c >= b and c >= d:
mid1_num = c
if b >= d:
mid2_num = b
min_num = d
else:
mid2_num = d
min_num = b
else:
mid1_num = d
if b >= c:
mid2_num = b
min_num = c
else:
mid2_num = c
min_num = b
elif b >= a and b >= c and b >= d:
max_num = b
if a >= c and a >= d:
mid1_num = a
if c >= d:
mid2_num = c
min_num = d
else:
mid2_num = d
min_num = c
elif c >= a and c >= d:
mid1_num = c
if a >= d:
mid2_num = a
min_num = d
else:
mid2_num = d
min_num = a
else:
mid1_num = d
if a >= c:
mid2_num = a
min_num = c
else:
mid2_num = c
min_num = a
elif c >= a and c >= b and c >= d:
max_num = c
if a >= b and a >= d:
mid1_num = a
if b >= d:
mid2_num = b
min_num = d
else:
mid2_num = d
min_num = b
elif b >= a and b >= d:
mid1_num = b
if a >= d:
mid2_num = a
min_num = d
else:
mid2_num = d
min_num = a
else:
mid1_num = d
if a >= b:
mid2_num = a
min_num = b
else:
mid2_num = b
min_num = a
else:
max_num = d
if a >= b and a >= c:
mid1_num = a
if b >= c:
mid2_num = b
min_num = c
else:
mid2_num = c
min_num = b
elif b >= a and b >= c:
mid1_num = b
if a >= c:
mid2_num = a
min_num = c
else:
mid2_num = c
min_num = a
else:
mid1_num = c
if a >= b:
mid2_num = a
min_num = b
else:
mid2_num = b
min_num = a
print("从大到小的顺序为:", max_num, mid1_num, mid2_num, min_num)
阅读全文