유형 오류 : +에 대해 지원되지 않는 피연산자 유형 : 'NoneType'및 'str'종료 상태 1
Nov 13 2020
텍스트를 계속 편집하지만 같은 오류가 계속 발생합니다!
내 코드 :
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)
아직 파이썬에 익숙하지 않음
답변
Barmar Nov 13 2020 at 07:10
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
괄호로 묶인 인수를 사용하지 않는 문이므로 Python 3에서는 일반 함수입니다.
PotatoPythonLearner Nov 13 2020 at 07:22
이 문자열의 끝에서 괄호를 제거하십시오.
print("There were two friends, their names are "
끝에 추가하십시오
random.choice(Outcomes)
따라서 다음과 같아야합니다.
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))