任何帮助,我需要输入一个带有负号的数字列表,python 3

问题描述 投票:-2回答:1

我尝试了此操作,但它给了我这个错误:(SyntaxError:扩展分配的非法表达式)

输入将是这样的:-2 4 -1

    x_forces, y_forces, z_forces = 0
    x_forces, y_forces, z_forces += map(int, input().split(' '))
python python-3.x negative-number
1个回答
0
投票

这是您要寻找的吗?

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)
© www.soinside.com 2019 - 2024. All rights reserved.