首页 > 解决方案 > 如何在一行中输入多个值?

问题描述

如何在一行中输入多个值?输出应类似于 a:8 b:5 c:6 d:4 e:0.1

我试过这个输入:

a, b, c, d, e = int(input(' '.format(a:, b:, c:, d:, e:)))

但这没有用。

标签: pythoninput

解决方案


你可以这样做:

a, b, c, d, e = input("Insert the 5 values: ").split()
print(f"a: {a}\nb: {b}\nc: {c}\nd: {d}\ne: {e}")

输入:

1 2 3 4 5

输出:

a: 1
b: 2
c: 3
d: 4
e: 5

推荐阅读