gpt4 book ai didi

python - "how to print multiple user inputs on one line"

转载 作者:行者123 更新时间:2023-12-01 06:57:00 25 4
gpt4 key购买 nike

基本上,我想要求用户输入任意数量的销售数字,然后在一个特定行上打印出所有输入,我该怎么做。

def main():   
num = int((input("Please enter sales figures: ")))

while (num != -1 ):
num = int(input("Please enter sales figures: "))

print("The sales figures entered were:", num)

main()

最佳答案

您可以将所有数字附加到列表中,然后打印列表,如下所示:

def main():
num = int((input("Please enter sales figures: ")))
list = []
list.append(num)

while num != -1:
num = int(input("Please enter sales figures: "))
list.append(num)

print("The sales figures entered were:", end=" ")
for num in list:
if num != -1:
print(num, end=", ")


main()

end=""参数使得它在同一行中打印。

关于python - "how to print multiple user inputs on one line",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58773382/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com