简体   繁体   English

如何让用户只输入 5 个整数/字符串 a 到列表中?

[英]How can I have the user input only 5 integers/strings a into a list?

My class is starting to add lists into our code.我的班级开始将列表添加到我们的代码中。 I understand how to have the user input information and loop it forever until the user types 'n' (or something like that) thus exiting the program.我了解如何让用户输入信息并永远循环,直到用户输入“n”(或类似的东西)从而退出程序。

My part of my current assignment is to have the user input 5 exam scores, store the scores into a list, and then display the list.我当前作业的一部分是让用户输入 5 个考试分数,将分数存储到列表中,然后显示列表。

How do I have the user input type in ONLY 5 exam scores and store it into a list?如何在仅 5 个考试分数中输入用户输入类型并将其存储到列表中?

Thank you fellow programmers for helping a new student to the coding world.感谢各位程序员帮助一个新学生进入编码世界。

请参阅有关 Python 中for循环的文档: https : //wiki.python.org/moin/ForLoop

import sys导入系统

def main(): print sys.argv def main(): 打印 sys.argv

if__name__ == ' main ': main() if__name__ == ' main ': main()

Add the command line argument that you want to the list将您想要的命令行参数添加到列表中

python hello.py aaa bbb ccc replace aaa bbb ccc with your stuff python hello.py aaa bbb ccc 用你的东西替换 aaa bbb ccc

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

相关问题 如何通过从用户输入中删除哪个值来从(整数和字符串)列表中删除整数? - How can I delete integers from list (of integers and strings) by taking which value to delete from user input? 如何在 Python 中将用户输入限制为仅整数 - How can I limit the user input to only integers in Python 如何在字符串/整数列表中仅选择整数? - How to select only integers in a list of strings/integers? 如何查找Python 3.3.0中用户输入是否包含在任意整数列表中 - How can I find if user input is inclusive in list of arbitrary integers in Python 3.3.0 Python。 如何对包含字符串和整数的列表求和? - Python. How can I sum a list with strings and integers? 如何从字符串列表中提取整数以创建公式? - How can I extract integers from a list of strings to create a formula? 如何将列表中的用户输入作为 Python 3 中的整数 - How do I take user input in a list as integers in Python 3 如何在 Python 中将用户输入限制为仅某些整数(即:仅在 1-100 之间,其中还包括 1 和 100) - How can I limit the user input to only certain integers (ie: Only between 1-100, which also includes 1 and 100) in Python 我如何让用户输入列表? - How do I have a user input a list? 如何使用字符串和整数打印列表理解并仅向字符串添加符号? - How to print a list comprehension with strings and integers and add a symbol only to the strings?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM