记得改参数
第七章本章作业
**
**
2、编码题
(1)、list1 = [1,2,3,4]
list1[5] = 9
print(list1)
(2)、list1 = []
for i in range(1,6):
print("请输入第%d个数"%(i))
students = int(input())
list1.append(students)
list1.sort()
if students < 0 :
print("输入有误,请输入正确的信息")
elif students >100 :
print("输入有误,请输入正确的信息")
print(“你输入的数是:”,list1)
(3)、import time
list1 = []
for i in range(1,6):
print("请输入第%d个数"%(i))
students = int(input())
if students < 0:
print("输入有误,请输入正确的信息")
tme = time.strftime("%Y-%m-%d %H:%M:%S")
print(tme)
continue
elif students >100 :
print("输入有误,请输入正确的信息")
tme = time.strftime("%Y-%m-%d %H:%M:%S")
print(tme)
continue
list1.append(students)
list1.sort()
while len(list1) < 5:
print("输入的数字不够")
again = int(input())
list1.append(again)
list1.sort()
print(“你输入的数是:”,list1)
tme = time.strftime("%Y-%m-%d %H:%M:%S")
print(tme)
(4)、ls = [15,8,7,9,8]
def mid_mean(ls):
new_list = []
for i in range(len(ls)):
new_item = (ls[i-1]+ls[i]+ls[i+1])/3
new_list.append(new_item)
return new_list
原因是return只能写在def里面的函数里面,不能缩进出来