|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
def a(*c,base = 3):
if c[-1] == 5:
result = (sum(c) - c[-1]) * 5
else:
result = sum(c) * base
return result
t = tuple(input()) #这里试图用input传入收集参数 但是失败了 失败原因TypeError: unsupported operand type(s) for +: 'int' and 'tuple'
print(a(t))
我想问的问题是:如何通过input传入多个参数(例如 *c想要10个参数 有什么办法可以通过input传入吗)
本帖最后由 isdkz 于 2022-3-12 14:59 编辑
- def a(*c,base = 3):
- if c[-1] == 5:
- result = (sum(c) - c[-1]) * 5
- else:
- result = sum(c) * base
- return result
- t = eval(input()) # 注意这里
- print(a(*t)) # 注意这里
复制代码
效果:
D:\>python test.py
1,2,3
18
D:\>python test.py
1,2,3,4,5
50
D:\>
|
|