Python While循环用于存储具有递增元组的记录

Python While循环用于存储具有递增元组的记录,python,Python,我已经创建了这段代码,但它只存储了一个值。我如何修改它以存储尽可能多的用户想要的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

我已经创建了这段代码,但它只存储了一个值。我如何修改它以存储尽可能多的用户想要的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

您正在使用元组存储学生记录(圆括号),该记录不可修改。也许可以尝试使用一个列表(方括号)?

不管我通过在顶层添加另一个带有空列表的while循环来解决它

while True:
     studentrec= []

studentrec.append (stdrecord)

元组是不可变的,可以使用列表或字典

通过阅读了解更多有关元组和其他数据结构的信息

用另一个数据结构替换元组数据结构应该可以解决您的问题