30,417
社区成员




题目:编写input()和output()函数输入,输出5个学生的数据记录。
#coding=utf-8
student = {}
N = int(input('人数:'))
def in_put(N):
for i in range(N):
i +=1
student[i] = {}
a = input('学号:')
student[i]['num'] = a
b = input('姓名:')
student[i]['name'] = b
student[i]['score'] = {}
for j in range(3):
j += 1
c = input('成绩:')
student[i]['score'][j] = c
print(student)
def out_put(N):
for i in range(N):
i += 1
print(student[i]['num'],student[i]['name'])
for j in range(3):
j += 1
print('{}:'.format(j),student[i]['score'][j])
if __name__ == '__main__':
in_put(N)
out_put(N)
用字典方法
题目:创建一个链表。
#coding=utf-8
if __name__ == '__main__':
lst = []
for i in range(5):
a = int(input('输入数:'))
lst.append(a)
print(lst)
循环向列表中加入元素
题目:反向输出一个链表。
#coding=utf-8
if __name__ == '__main__':
lst = []
for i in range(5):
a = int(input('输入数:'))
lst.append(a)
print(lst)
lst.reverse()
print(lst)
reverse方法,没有返回值
题目:列表排序及连接。
#coding=utf-8
a = [2,1,5,3,9,6]
b = [4,5,7,3,2,1]
a.sort()
print(a)
print(a+b)
a.extend(b)
print(a)
sort将列表排序,两个列表连‘+’还有extend方法
题目:放松一下,算一道简单的题目。
#coding=utf-8
for i in range(5):
n = 0
if i != 1:
n += 1
if i ==3:
n += 1
if i == 4:
n += 1
if i != 4:
n += 1
if n == 3:
print(64+i)
..........