簡體   English   中英

如何接收帶有負號的數字列表?

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

我試過這個,但它給了我這個錯誤: 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(' '))

這是你要找的嗎?

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