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

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

问题描述

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

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

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

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

推荐答案

input函数仅接受一个参数,即消息.但是,要解决此问题,一种选择是使用带有空结束符的print语句,如下所示:

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天全站免登陆