给定三个个位数,编写一个代码来找到中间数字最小的最大数字。例如,假设输入为 3, 9, 8,则生成的数字为 938。
输入格式
第一行包含第一个个位数,d1
下一行包含第二个个位数,d2
下一行包含第三个个位数,d3
输出格式
打印形成的数字
为什么我的代码是错误的?
d1=int(input())
d2=int(input())
d3=int(input())
lists=[d1,d2,d3]
y=lists.sort()
a=y[2]
b=y[1]
c=y[0]
num=(int(a)*100)+(int(c)*10)+int(b)
print(num)
最佳答案
.sort()
修改原始列表而不返回值,这里你想要的是这样的:
d1=int(input())
d2=int(input())
d3=int(input())
lists=[d1,d2,d3]
lists.sort()
a=lists[2]
b=lists[1]
c=lists[0]
num=(int(a)*100)+(int(c)*10)+int(b)
print(num)
关于python - 根据给定条件组成一个数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69572974/