一、首先我们可以先用input函数来输入并存储这三个数,然后将他们放入一个列表中,再排序输出。 二、用到的函数及用法 1.input函数 变量=input() 2.int函数 int函数用于将字符串变为数值。input函数生成的变量是字符串,所以要用int函数将变量转换成数值 3.append函数。 用于向列表中添加元素 用法:列表.apend(要添加的元素) 4.sort函数 用法:要排序的列表名sort() 该函数用于将函数中的元素排序,也可以用于排列字母。 三、
num
=[]
x
=int(input("please enter a number: "))
num
.append
(x
)
y
=int(input("Please enter a number again: "))
num
.append
(y
)
z
=int(input("please enter a number last: "))
num
.append
(z
)
num
.sort
()
print(num
)
四、也可以用for循环来实现
num
=[]
for i
in range(3):
x
=int(input("please enter a number: "))
num
.append
(x
)
num
.sort
()
print(num
)
转载请注明原文地址:https://tech.qufami.com/read-26930.html