我正在写一个简短的程序,使它看起来像电脑被黑客攻击。
我要运行它,让计算机躺在身边,看看人们的反应。
但是,当我尝试使用time.sleep.
时出现此语法错误time.sleep.
有人可以帮忙吗?
import time print("Connecting to Server...") print("Connected!") response = input("Proceed with Hack? Y/N: ") if response == "Y": { print("Uploading File: 10%") time.sleep(2) print("Uploading File: 20%") time.sleep(2) print("Uploading File: 30%") time.sleep(2) print("Uploading File: 40%") time.sleep(2) print("Uploading File: 50%") time.sleep(2) print("Uploading File: 60%") time.sleep(2) print("Uploading File: 70%") time.sleep(2) print("Uploading File: 80%") time.sleep(2) print("Uploading File: 90%") time.sleep(2) print("Uploading File: 99%") time.sleep(1) print("File Uploaded!") print("Virus Injection Started...") time.sleep(6) print("Virus Injection Complete!") }
Python不使用花括号,这可能是你的语法错误的原因,只是使用制表符缩进。
你正在使用大括号,它们不是Python语法的if
语句,也不是循环( for, while
)。 花括号用于其他编程语言。 例如C和Java使用大括号来定义属于if
语句的代码行,但是它不像Python中那样。
在Python中,只要记住每行以4个空格开始的缩进将属于输入if
时执行的代码。 这个Python的语法也扩展到了循环,函数定义,类定义等等。
为您的代码删除大括号,并保持缩进。
举一个简单的例子:
a = 0 if a == 0: a = 1 # This line is inside the if statement b = 1 # This line is also inside the if statement a = 2 # Outside the if statement