为什么这里有“打字错误”?

2024-09-26 18:05:14 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在制作一个快速的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()

错误:

^{pr2}$

如果有需要,我愿意提供更多的信息。在


Tags: or代码import游戏time错误notfunction
2条回答

您混淆了Python语法的两个非常不同的东西。[]是一个索引符号;myindexable[i]表示myindexable中的第i项。()是调用函数的符号;myfunc(n)用参数n调用函数myfunc。在

sleep是一个函数/方法,而不是一个可索引的对象。你这样称呼它:

sleep(time)

不像:

^{pr2}$

相关问题 更多 >

    热门问题