简体   繁体   English

是否有一种简单的方法可以将用户输入作为整数使用,并将该整数用作下一个问题被问多少次的量?

[英]Is there a simple way to take user input as an integer and use that integer as an amount for how many times the next question is asked?

I am trying to create a list from user input but I need to find a way to ask how many integers the user wants, and take their answer to then ask them to enter an integer, depending on how many integers they want. 我正在尝试从用户输入创建一个列表,但我需要找到一种方法来询问用户想要多少个整数,然后根据他们想要的整数数量,让他们回答然后让他们输入一个整数。

This is for my Computer Science homework and we are learning how to first use list and user input. 这是我的计算机科学作业,我们正在学习如何首先使用列表和用户输入。

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)

I expect the output to look like this: 我希望输出看起来像这样:

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

There is helpful comments on your question, if you still can't figure out how to do, here it is: 对你的问题有一些有用的评论,如果你仍然无法弄清楚如何做,这里是:

def numbers():
    list1 = []
    list_amount = int(input("How many integers would you like to add to the list? "))

    for i in range(list_amount):
        num = int(input("Enter an integer: "))
        list1.append(num)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 检查列表中 integer 在 python3 中与用户输入一起出现的次数 - checking a list for how many times an integer appears with user input in python3 如何在python3中将一个简单的整数矩阵作为输入 - How to take a simple integer matrix as input in python3 如何多次显示 integer - How to display an integer many times 如何向用户询问循环数量,然后更改提出的问题 - How to ask user for loop amount and then changing the question asked 我想制作一个程序,将用户的整数输入求和。 没有固定数量的参数 - I want to make a program that take integer input from user and sum those. There is no fixed amount of parameter 获取一个列表和一个 integer 作为用户的输入 - Take a List and an integer as input from user 如何取整数并在其上使用小数 - how to take an integer and use a fraction on it 我想从用户那里获得 integer 输入,然后让 for 循环遍历该数字,然后多次调用 function - I want to get an integer input from a user and then make the for loop iterate through that number, and then call a function that many times 如何在 python 中输入一对浮点数和 integer - How to take input in pair of float and integer in python 如何找到用户输入是整数并使用相同的输入与现有的整数值进行比较 - how to find the user input is integer and use same input to compare with existing integer value
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM