一个从第一个数开始每隔一个数相加,第二个和从第二个数开始。 榜样
Tuple= (1, 2, 3, 4, 5, 6, 7, 8)
Sum1= 1+3+5+7
Sum2= 2+4+6+8
以下是我目前掌握的情况:
def everyOtherSumDiff(eg):
a=0
b=0
for i in (eg, 2):
a+=i
return a
eg=(1, 2, 3, 4, 5, 6, 7, 8)
print(everyOtherSumDiff(eg))
我不知道如何从用户输入中获取元组,而且我也没有对元组做过很多工作,所以我不知道如何将它们彼此相加,尤其是从不同的起点开始
任何帮助都将不胜感激
我将以CovFe19的答案为基础,添加元组部分:
希望这对输入的生成和元组的存储有所帮助
如您所见,您必须调用创建的元组,并将输入添加为元组
(user_input,)
。这将把插入到输入中的每个值添加到my_tuple
的最后一个索引中对此,可以使用切片语法[start:stop:step]
相关问题 更多 >
编程相关推荐