首页 > 解决方案 > 类型错误:+ 不支持的操作数类型:“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还是新手

标签: 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 中,printis 是一个语句,因此它不带括号中的参数,但在 Python 3 中,它是一个普通函数。


推荐阅读