python - 类型错误:+ 不支持的操作数类型:“NoneType”和“str”退出状态 1
问题描述
我一直在编辑我的文本,但我一直收到同样的错误!
我的代码:
import random
Female_Characters = ["Emily", "Ariel", "Jade", "Summer"]
Male_Characters = ["Blake", "Max", "Jack", "Cole", "Daniel"]
PlacesToMeet = ["Beach", "Park", "Train Station", "Cave"]
SheSaid = ["Lets go explore!", "I'm tired", "I saw a purple frog", "My tounge hurts"]
HeSaid = ["I didnt get much sleep", "I wanna go inside that cave!", "Oh, ok"]
Outcomes = ["They never got to", "They were never found again.", "They enjoyed their day and went to
get Ice Cream!"]
ChosenFemale = random.choice(Female_Characters)
ChosenMale = random.choice(Male_Characters)
ChosenMeet = random.choice(PlacesToMeet)
ChosenShesaid = random.choice(SheSaid)
ChosenHeSaid = random.choice(HeSaid)
print ("There were two friends, their names are ") + (ChosenMale) + (", and ") + (ChosenFemale) + (".") + ("One day when they were at the") + (ChosenMeet) + (", ") + (ChosenFemale) + (" Said, ") + (ChosenShesaid) + (". Then") + (ChosenMale) + (" Said ") + (ChosenHeSaid) + (". After that, ") + random.choice(Outcomes)
python还是新手
解决方案
您在行中有不正确的括号print
。
print("There were two friends, their names are " + ChosenMale + ", and " + ChosenFemale + "." + "One day when they were at the" + ChosenMeet + ", " + ChosenFemale + " Said, " + ChosenShesaid + ". Then" + ChosenMale + " Said " + ChosenHeSaid + ". After that, " + random.choiceOutcomes)
您的代码正在调用
print("There were two friends, their names are ")
返回None
,然后尝试将其与所有其他字符串连接起来。
也许您正在遵循 Python 2.x 的说明。在 Python 2 中,print
is 是一个语句,因此它不带括号中的参数,但在 Python 3 中,它是一个普通函数。
推荐阅读
- python - Python线性回归组合问题
- php - WooCommerce 的 Mailchimp:删除同步问题的订阅者标签
- amazon-s3 - AWS Glue 和 S3 访问点
- node.js - 如何在 CodeIgniter 4 中集成节点包?
- bash - Bash脚本完成后没有退出,为什么?
- angularjs - 健全性检查:是否可以在 HLS(m3u8)视频流和 angularjs 应用程序(ui)之间进行代理?
- python - 用列表理解解决方案替换 numpy isin
- flutter - Flutter 设置状态未使用新数据更新我的 UI
- python - 瑞典语字符解码错误:这是 API 的错还是我的错?
- python - 无法创建 urls.yaml 以使用 urlwatch