用Python编写程序,输入格式为(1),(2,3,),(1,2,3,4),分别计算此三个元祖的长度,并统计三个元祖的长度之和,把以上四个数据合并到一个新列表,并输出该新列表
时间: 2024-05-12 09:19:14 浏览: 79
代码如下:
```python
tuple1 = (1,)
tuple2 = (2, 3,)
tuple3 = (1, 2, 3, 4)
len1 = len(tuple1)
len2 = len(tuple2)
len3 = len(tuple3)
total_len = len1 + len2 + len3
new_list = [tuple1, tuple2, tuple3, total_len]
print(new_list)
```
输出结果为:
```
[(1,), (2, 3), (1, 2, 3, 4), 8]
```
阅读全文