代码的错误是什么:在time方法中获取无效语法

时间:2017-09-22 22:17:13

标签: python python-3.x delay python-3.6 timedelay

#multiplication table with time delay
import time

num=int(input("Enter the value for which you want the multiplication table for:"))

print("The table will be as:\n")
for i in range(1,11):
    {
        print(num,"x",i,"=",num*i,"\n")
        time.sleep(3)
    }

print("The table is completed")
input("Press enter to exit")

编译器在此代码中出现此代码

time.sleep(3)

它显示无效语法错误。这段代码中的错误是什么?

1 个答案:

答案 0 :(得分:4)

抱怨{}。在Python中,它们没有定义块,它们定义了一个字典。因此,{}中的内容应该是字典文字,但这不是你所拥有的。你可能想要:

for i in range(1, 11):
    print(num, "x", i, "=", num * i, "\n")
    time.sleep(3)

(注意,缩进是定义块。)