K. Taylor
K. Taylor

Reputation: 23

Multiple Arguments in an Input?

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?

Upvotes: 2

Views: 22544

Answers (3)

Mohammed Towfiq
Mohammed Towfiq

Reputation: 1

Of course, it is easy to make the variable within the str () function to convert it from a number to a string and to separate all the arguments using "+" and do not use "-" where programmatically when using "+" Python will be considered as one string

grade = input ("quiz 1: ")
count = 1
while grade != "" :
    count += 1
    grade = input ("quiz "+ str(count) + ": ")

Upvotes: 0

mechanical_meat
mechanical_meat

Reputation: 169334

Use .format, e.g.:

count = 0
while grade != "" :
    count += 1
    grade = input('quiz {}:'.format(count))

Upvotes: 1

m_callens
m_callens

Reputation: 6360

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()

Upvotes: 1

Related Questions