从用户输入

时间:2018-02-05 23:30:01

标签: python python-3.x

我有以下代码

UserInput = input("Input a number :")
Numbers = []
for index in range(int(UserInput)):
    print("Entry " + str(index+1) + " is ")
    Numbers.append(input())

我希望输出看起来像这样

Input a number :2
Entry 1 is 1
Entry 2 is 4

但是我使用我当前的代码 - Python 3.6

获得了以下内容
Input a number :2
Entry 1 is 

1
Entry 2 is 

4

我想我在某处遗漏了一些简单的东西?

2 个答案:

答案 0 :(得分:1)

这有效:

UserInput = input("Input a number :")
Numbers = []
for index in range(int(UserInput)):
    Numbers.append(input("Entry " + str(index+1) + " is ")) # change here

答案 1 :(得分:0)

参考您的回答: -

UserInput = input("Input a number :")
Numbers = []
for index in range(int(UserInput)):
    print("Entry " + str(index+1) + " is ",end='')
    Numbers.append(input())