TypeError: not enough arguments for format string when using %s

前端 未结 2 1376
孤城傲影
孤城傲影 2021-01-02 07:32

this is my code

import sys
name = input(\"Enter your name:\")
last_name = input(\"Enter your last name:\")
gender = input(\"Enter your gender:\")
age = input         


        
2条回答
  •  时光说笑
    2021-01-02 08:17

    You need to put your arguments for string formatting in parenthesis:

    print (... % (name, last_name, gender, age))
    

    Otherwise, Python will only see name as an argument for string formatting and the rest as arguments for the print function.


    Note however that using % for string formatting operations is frowned upon these days. The modern approach is to use str.format:

    print ("So your name is {}, your last name is {}, you are {} and you are {} years old".format(name, last_name, gender, age))
    

提交回复
热议问题