Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/337.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 文件";abc1234.py“;,第9行时间。睡眠(3)^缩进错误:应为缩进块_Python - Fatal编程技术网

Python 文件";abc1234.py“;,第9行时间。睡眠(3)^缩进错误:应为缩进块

Python 文件";abc1234.py“;,第9行时间。睡眠(3)^缩进错误:应为缩进块,python,Python,我是编程新手,我试图使用terminal运行这个python程序,结果出现错误:文件“abc1234.py”,第9行time.sleep(3) 缩进错误:应为缩进块 ^ import webbrowser import time time_total=3 time_count=0 print (" the current time is " +time.ctime()) while(time_count<time_total): time.sleep(3) webbrowser.open(

我是编程新手,我试图使用terminal运行这个python程序,结果出现错误:
文件“abc1234.py”,第9行time.sleep(3)
缩进错误:应为缩进块
^

import webbrowser
import time
time_total=3
time_count=0
print (" the current time is " +time.ctime())
while(time_count<time_total):
time.sleep(3)
webbrowser.open("https://www.youtube.com/results?search_query=raabta+song+deepika")
time_count= time_count+1
导入网络浏览器
导入时间
总时间=3
时间计数=0
打印(“当前时间为”+time.ctime())

而(time_count不确定您是如何根据输入设置格式的。 但您的代码应该如下所示:

import webbrowser
import time
time_total = 3
time_count = 0
print (" the current time is " + time.ctime())
while(time_count < time_total):
    time.sleep(3)
    webbrowser.open("https://www.youtube.com/results?search_query=raabta+song+deepika")
    time_count = time_count + 1
导入网络浏览器
导入时间
总时间=3
时间计数=0
打印(“当前时间为”+time.ctime())
而(时间计数<时间总数):
时间。睡眠(3)
网络浏览器打开(“https://www.youtube.com/results?search_query=raabta+宋+迪皮卡)
时间计数=时间计数+1

您必须缩进while块内的所有代码。您必须没有正确缩进第9行的
时间。sleep(3)
。解释器希望在代码有效的while循环的冒号后面至少有一行缩进。但是,我正在使用文本编辑器“TextWrangler”和“while loop”我是否必须手动添加空格,因为:在while循环中,它直接将我带到下一行,而不必像在while循环中那样添加空格。您可以尝试使用tab键吗?但是,我认为如果它支持python语言,在首选项中的某个位置,您可以启用自动缩进和定义我不确定,因为我个人不使用TextWrangler。这很有效。谢谢@dor ronSure thing很高兴能帮上忙