输入中有多个参数? [英] Multiple Arguments in an Input?

查看:15
本文介绍了输入中有多个参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

初学者程序员在这里.我正在尝试编写一个程序,该程序将要求用户提供测验成绩,直到他们输入空白输入为止.另外,我试图让输入从显示quiz1:"到quiz2:"、quiz3:"等等,每次用户输入新的测验成绩.像这样:

quiz1: 10测验 2:11测验 3:12

这是我到目前为止所写的内容:

grade = input ("quiz1:")计数 = 0而等级 != "" :计数 += 1等级=输入(测验",计数,:")

当我在输入中输入一个空白值时,我已经成功地使我的程序结束,但是当我尝试为测验成绩输入一个整数时,我收到以下错误:

回溯(最近一次调用最后一次):文件C:\Users\Kyle\Desktop\test script.py",第 5 行,在 <module>等级=输入(测验",计数,:")类型错误:输入预计最多 1 个参数,得到 3

如何在与等级输入相关的括号内包含多个参数?

解决方案

input 函数只接受一个参数,即消息.但是,要绕过它,一种选择是在前面使用带有空结尾字符的打印语句,如下所示:

<预><代码>...而等级 != "":计数 += 1打印(测验",计数,:",结束=")等级 = 输入()

Beginner Programmer here. I'm trying to write a program that will ask a user for a quiz grade until they enter a blank input. Also, I'm trying to get the input to go from displaying "quiz1: " to "quiz2: ", "quiz3: ", and so on each time the user enters a new quiz grade. Like so:

quiz1: 10 
quiz2: 11
quiz3: 12

Here's what I've written so far:

grade = input ("quiz1: ")
count = 0
while grade != "" :
    count += 1
    grade = input ("quiz ", count, ": ")

I've successfully managed to make my program end when a blank value is entered into the input, but when I try to enter an integer for a quiz grade I receive the following error:

Traceback (most recent call last):
  File "C:\Users\Kyle\Desktop\test script.py", line 5, in <module>
    grade = input ("quiz ", count, ": ")
TypeError: input expected at most 1 arguments, got 3

How do I include more than one argument inside the parenthesis associated with the grade input?

解决方案

The input function only accepts one argument, being the message. However to get around it, one option would be to use a print statement before with an empty ending character like so:

.
.
.
while grade != "":
    count += 1
    print("quiz ", count,": ", end="")
    grade = input()

这篇关于输入中有多个参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆