简体   繁体   English

Python 语法错误:字符串连接的语法无效

[英]Python syntax error: invalid syntax on string concatenation

I'm new to python coding and working on a small chatbot project.我是 python 编码和一个小型聊天机器人项目的新手。 What is the problem in the last line of code?最后一行代码有什么问题? I'm not sure.我不确定。

favanimal = input("What is your favorite animal?")

time.sleep(2)
print(favanimal + ", I like that choice")

time.sleep(2)
print("One more question, this one is extremely important, so choose carefully!")

time.sleep(2)
petname = input("If you had a pet" + favanimal "what would you name it?")

You are missing a + after favanimal in the last line.您在最后一行的favanimal之后缺少一个+ so just change it from所以只要改变它

petname = input("If you had a pet" + favanimal "what would you name it?")

to

petname = input("If you had a pet" + favanimal + "what would you name it?")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM