-4
오류 수정에 도움이 필요합니다.Python에서 "TypeError : 'str'객체를 호출 할 수 없습니다."를 수정할 수 없습니다.
import random
def game():
capitals={"England":"London","France":"Paris","Belgiom":"Brussels",\
"Canada":"Ottawa","China":"Beijing","Cyprus":"Nicosia",\
"Cuba":"Havana","Egypt":"Cairo","Greece":"Athens",\
"Ireland":"Dublin","Italy":"Rome","a":"A","B":"B"}
wrong=[]
right=[]
incorrect_answers = False
while len(capitals)>0:
pick = random.choice(list(capitals.keys()))
correct_answer = capitals.get(pick)
print ("What is the capital city of" + pick + "?")
answer = input("Your answer: ")
if answer.lower() == correct_answer.lower():
print ("That's Correct!\n")
del capitals[pick]
right.append(pick)
else:
print ("That's Incorrect.\n")
print ("The correct answer is" + correct_answer + "\n")
wrong.append(pick)
incorrect_answers = True
del capitals[pick]
print ("You got ",len(right), "/", len(wrong))
top = len(right)
bottom = len(wrong)
perc = float((top/bottom) * 100)
print(perc)
if incorrect_answers:
print ("Here are the ones that you may want to brush up on:\n")
for each in wrong:
print (each)
else:
print ("Perfect!")
def help():
print("do you neeeded efhdufghaf dfgjn")
while True:
input = input("what do you want to do? help or play?")
if input == "help":
help()
break
if input == "play":
print("you want to play")
game()
break
오류가있는 위치를 알 수 있도록 추적 코드를 제공하십시오. – user2097159
오류 메시지에 나타나는'Traceback (가장 최근 호출 마지막) :'~'TypeError : 'str'객체가 호출 가능하지 않음 '사이의 행은 디버깅시 진품 금광이며 문제의 원인이되는 코드 영역을 가리 킵니다 당신은 거의 모든 질문에 대해 끝까지 확인해야합니다. – zehnpaard
지금 고칠 수 있습니다. 그러나 어쨌든 고마워. 이것은 나의 첫 번째 게시물이므로 모든 규칙을 모릅니다 ... – LWoodroofe