简体   繁体   中英

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 .

The input will be something like this: -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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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