【发布时间】:2017-02-28 19:12:37
【问题描述】:
我的代码有什么问题?我不断收到错误 TypeError: 'str' object is not callable。我不明白为什么我一直收到这个错误,当一切都被定义并在需要时被强制到 str 时,如果不是超过需要的话。
import time
hallNumber = ""
if hallNumber == str(1):
print('You find a window')
else :
print('You find what you think is a door')
def dispIntro():
text_file = open("E:\Intro_game_develop\projects\project_one\intro.txt", 'r')
whole_thing = text_file.read()
print(whole_thing)
text_file.close()
def chooseHall():
hall = ''
while hall != '1' and hall != '2':
print('Which hall do you choose to go down? 1, or 2')
hall = input()
return hall
def checkHall(chosenHall):
print('You walk down the hall...')
time.sleep(1)
print('You walk towards the light...')
time.sleep(1)
print('You reach out for it and...')
time.sleep(1)
##hallNumber = ""
##
##if hallNumber == str(1):
## print('You find a window')
##else :
## print('You find what you think is a door')
def chosenPath(hallNumber):
print("I'm in chosenPath")
path = str(hallNumber())
if path == str(hallNumber(1)):
text_file = open("E:\Intro_game_develop\projects\project_one\window.txt", 'r')
whole_thing = text_file.read()
print(whole_thing)
text_file.close()
else:
text_file = open("E:\Intro_game_develop\projects\project_one\door.txt",'r')
whole_thing = text_file.read()
print(whole_thing)
text_file.close()
return path
【问题讨论】:
-
hallNumber(1)应该做什么? -
或者甚至只是上面一行的
hallNumber(),就此而言...... -
你将hallNumber设置为一个字符串,然后你称之为hallNumber(),但它不是一个函数,不能像函数一样调用一个字符串
-
提供运行脚本时运行的实际代码..