首页 > 解决方案 > 有没有一种简单的方法可以将用户输入作为整数并使用该整数作为下一个问题被问多少次的数量?

问题描述

我正在尝试根据用户输入创建一个列表,但我需要找到一种方法来询问用户想要多少个整数,然后根据他们想要多少个整数来回答他们然后要求他们输入一个整数。

这是我的计算机科学作业,我们正在学习如何首先使用列表和用户输入。

def numbers():
    list1 = []
    list_amount = int(input("How many integers would you like to add to the list? "))
    print("Enter an integer: ")
    for i in range(list_amount):
        print "Enter an integer: {}".format(list_amount)

我希望输出看起来像这样:

How many integers would you like to add to the list? 7
Enter an integer: 54
Enter an integer: 91
Enter an integer: 23
Enter an integer: 8
Enter an integer: -66
Enter an integer: 39
Enter an integer: 2

标签: pythonpython-2.7listuser-input

解决方案


推荐阅读