Error - input expected at most 1 argument, got 3

╄→гoц情女王★ 提交于 2019-11-28 02:08:14

A simple (and correct!) way to write what you want:

score = int(input('Please enter your score for test ' + str(y) + ': '))

Because input does only want one argument and you are providing three, expecting it to magically join them together :-)

What you need to do is build your three-part string into that one argument, such as with:

input("Please enter your score for test %d: " % y)

This is how Python does sprintf-type string construction. By way of example,

"%d / %d = %d" % (42, 7, 42/7)

is a way to take those three expressions and turn them into the one string "42 / 7 = 6".

See here for a description of how this works. You can also use the more flexible method shown here, which could be used as follows:

input("Please enter your score for test {0}: ".format(y))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!