python - 有没有一种简单的方法可以将用户输入作为整数并使用该整数作为下一个问题被问多少次的数量?
问题描述
我正在尝试根据用户输入创建一个列表,但我需要找到一种方法来询问用户想要多少个整数,然后根据他们想要多少个整数来回答他们然后要求他们输入一个整数。
这是我的计算机科学作业,我们正在学习如何首先使用列表和用户输入。
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
解决方案
推荐阅读
- javascript - 突出显示最小/最大值表jquery
- cordova - 尝试在 Android 设备上运行 Geolocation 时如何解决 Babel 问题?
- java - ltree postgres type using spring data jpa -- 在 postgres 中定义函数和强制转换后出现语法错误
- python - Python - 仅从文本文件中读取最后一行
- python - 索引 0 处的无效数组元素:需要 datetime.date 或 datetime.datetime 实例,得到 'int' asyncpg
- alpacajs - 羊驼 - 是否有 onReady 表格?
- flutter - Flutter 改变系统导航栏图标亮度
- angular - 子路由组件看不到的可重用组件
- javascript - 如何添加到 chrome 存储中已经存在的数组?
- reactjs - 从 React 中的配置文件动态命名组件