又到了一年一度的牛客运动会,Tom和Andy报名参加了项目, 但由于比赛前一天,Andy喝了太多碳酸饮料,导致身体不适,所以临时让Allen上场了, 换人参赛需要修改参赛名单,请完成以下内容模拟整个过程。 请创建一个依次包含字符串'Tom'和'Andy'的元组my_tuple, 先使用print()语句一行打印字符串'Here is the original tuple:',再使用for循环将元组my_tuple的内容打印出来; 请使用try-except代码块执行语句my_tuple[1] = 'Allen', 若引发TypeError错误,先输出一个换行,再使用print()语句一行打印字符串"my_tuple[1] = 'Allen' cause cause a TypeError: 'tuple' object does not support item assignment"; 再重新对my_tuple赋值一个新元组,新元组依次由字符串'Tom'和'Allen'构成。 输出一个换行,先使用print()语句一行打印字符串'The tuple was changed to:',再使用for循环将元组my_tuple的内容打印出来,确定修改无误。
输入描述:


输出描述:
按题目描述进行输出即可(注意前后两个输出部分需以一个空行进行分隔)。Here is the original tuple:TomAndymy_tuple[1] = 'Allen' cause a TypeError: 'tuple' object does not support item assignmentmy_tuple was changed to:TomAllen
加载中...