Python time.sleep 语法错误
Python time.sleep syntax error
我正在编写一个简短的程序,使计算机看起来像是被黑客入侵了。
我打算 运行 它并让计算机闲置,看看人们的反应。
但是,当我尝试使用 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
我正在编写一个简短的程序,使计算机看起来像是被黑客入侵了。
我打算 运行 它并让计算机闲置,看看人们的反应。
但是,当我尝试使用 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