只是说我知道这个问题之前已经得到了回答,但我发现很难将它应用到我的情况中。
cake = ('Chocolate Cakes')
cake_amnt = int(input('How many',cake,'would you like to make?'))
当我运行上面的代码时,我收到此错误:
TypeError: input expected at most 1 arguments, got 3
我的问题是:这个错误是什么意思?如何修复我的代码以便我不会收到错误?
答案 0 :(得分:3)
input
只接受一个字符串,因此要连接而不是
cake_amnt = int(input('How many',cake,'would you like to make?'))
您应该使用format
来构建字符串
cake_amnt = int(input('How many {} would you like to make?'.format(cake)))
或使用+
运算符执行连接
cake_amnt = int(input('How many ' + cake + ' would you like to make?'))