我正在建立一个快速的1小时游戏,大约一半的时间通过,并TypeError: 'builtin_function_or_method' object is not subscriptable发生错误.我不知道为什么会这样,使用time.sleep[x]函数似乎有些问题.我的完整错误和代码如下.
码:
import time
import random
def intro():
print("You are playing a game...")
time.sleep[3]
print("of chance.")
time.sleep[1.5]
print("Enter [1] to continue.")
introChoice=''
while introChoice not in ['1']:
introChoice=input("> ")
if introChoice=="1":
tutorial()
Run Code Online (Sandbox Code Playgroud)
错误:
You are playing a game...
Traceback (most recent call last):
File "/Users/jacob/Documents/a game of chance.py", line 126, in <module>
intro()
File "/Users/jacob/Documents/a game of chance.py", line 9, in intro
time.sleep[3]
TypeError: 'builtin_function_or_method' object is not subscriptable
Run Code Online (Sandbox Code Playgroud)
任何帮助表示赞赏,如果有必要,我愿意提供更多信息.
sleep是一个函数/方法,而不是一个可索引的对象.你这样称呼它:
sleep(time)
Run Code Online (Sandbox Code Playgroud)
不喜欢:
sleep[time]
Run Code Online (Sandbox Code Playgroud)