简体   繁体   English

如何接收带有负号的数字列表?

[英]How to take in a list of numbers with negative signs?

I tried this but it gave me this error: SyntaxError: illegal expression for augmented assignment .我试过这个,但它给了我这个错误: SyntaxError: illegal expression for augmented assignment

The input will be something like this: -2 4 -1输入将是这样的: -2 4 -1

x_forces, y_forces, z_forces = 0
x_forces, y_forces, z_forces += map(int, input().split(' '))

Is this what you're looking for?这是你要找的吗?

x_forces, y_forces, z_forces = 0, 0, 0
n = [i for i in map(int, input().split(' '))]

x_forces += n[0]
y_forces += n[1]
z_forces += n[2]

print(x_forces, y_forces, z_forces)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM