【问题标题】:How to take in a list of numbers with negative signs?如何接收带有负号的数字列表?
【发布时间】:2020-10-04 00:19:48
【问题描述】:

我试过了,但它给了我这个错误:SyntaxError: illegal expression for augmented assignment

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

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

【问题讨论】:

  • 您可能想向我们提供您使用的语言
  • 我正在使用 python 3
  • 你想要做的只是删除+=并将其设置为=
  • 你的输出应该是什么样子的?

标签: python python-3.x negative-number


【解决方案1】:

这就是你要找的吗?

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)

【讨论】:

    猜你喜欢
    • 2019-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-10-05
    • 1970-01-01
    • 2021-04-13
    相关资源
    最近更新 更多