有人可以解释为什么我不能在目标变量中使用your_name吗?
my_name = "Bryson"
my_age = 29
your_name = input ("What is your name? ")
your_age = input ("What is your age? ")
print ("My name is", my_name,", and I am", my_age, "years old.")
print ("Your name is", your_name,", and you are", your_age,".")
print("Thank you for buying my book,", your_name,"!")
goal = input ("What was your favorite part of the book,", your_name, "?")
print("Awesome!")
我得到的错误是:
goal = input ("What was your favorite part of the book,", your_name, "?")
TypeError: input expected at most 1 arguments, got 3
答案 0 :(得分:1)
你得到了这个错误,因为你实际上只给了input
函数3个参数,当它只期望1时(即字符串提示符)。
In input ("What was your favorite part of the book,", your_name, "?")
---------------------------------------- , ---------, ---
带下划线的部分是以逗号分隔的参数:一个字符串("什么是.... book",一个变量your_name
,另一个字符串,"?&# 34;
我认为你想要的是
goal = input("What was your favorite part of the book, " + your_name + "?")
这里连接运算符+
将这些成分组合成一个字符串 - 字符串是input
期待的一个参数
答案 1 :(得分:0)
答案 2 :(得分:-1)
input(print("What was your favorite part of the book, " + your_name + "?"))