我已经创建了这段代码,但它只存储一个值我如何修改它,以存储尽可能多的std记录,许多用户想要的
while True:
name=input('please provide name of a student')
courses=[]
stdrecord=()
while True:
course=input('please provide a course')
courses.append(course)
print(courses)
ch_course=input('would you like to enter another course yes/no')
if ch_course=='yes':
continue
else:
stdrecord+=((name,courses))
break
ch_name=input('would you like to enter another record yes/no')
if ch_name=='no':
print (stdrecord)
break
元组是不可变的,可以使用列表或字典
通过this了解有关元组和其他数据结构的更多信息
用另一个数据结构替换元组数据结构应该可以解决您的问题
不管怎样,我通过在顶层添加另一个while循环和一个空列表来解决它
和
您正在使用元组存储学生记录(圆括号),这是不可修改的。可能尝试使用列表(方括号)
相关问题 更多 >
编程相关推荐