Multiple Arguments in an Input?

前端 未结 3 1623
死守一世寂寞
死守一世寂寞 2021-01-25 16:50

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 disp

相关标签:
3条回答
  • 2021-01-25 17:34

    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()
    
    0 讨论(0)
  • 2021-01-25 17:40

    Use .format, e.g.:

    count = 0
    while grade != "" :
        count += 1
        grade = input('quiz {}:'.format(count))
    
    0 讨论(0)
  • 2021-01-25 17:44

    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) + ": ")
    
    0 讨论(0)
提交回复
热议问题