目前,我正在使用Mac终端学习Python基础知识,在定义函数时我不知道如何编写新行,因为每当我点击"Enter“时,它就会抛出一个错误。
>>> def f():
... a = 10
File "<stdin>", line 2
a = 10
^
IndentationError: expected an indented block after function definition on line 1
我正在用python 3做一个提问程序,我用的是下面的代码
print ('how old are you?')
age = input ('age :')
if age < 18): print('Okay')
当我运行它时,有一条消息说
if age < (18):
^
IndentationError: unexpected indent
我该怎么办?
我向程序中添加了一个简单的打印变量行,它给了我一个IndentationError。代码使用"print yes“行进行注释,如下所示,但当我取消注释时,我得到错误:
错误:
factors.append(yes)
^
IndentationError: unexpected indent
代码:
n = 1
x = int(raw_input("What is the number you would like largest prime factor of?"))
factors= []
checklist = []
primefactors = []
while
有人能告诉我在这个Python代码示例中我做错了什么吗?
for i in range(len(Adapters)):
print Adapters[i]
我正在尝试列出/打印数组内容,但代码在打印命令时显示错误:IndentationError: expected an indented block
我是python的新手,所以请原谅任何基本的错误。我从一个网站上获取了这段代码(它看起来相当简单),所以我认为它会起作用。基本上,我希望这个代码块打印出2015到2016年之间的所有日期。据我所知,缩进看起来没问题。我也试过调整缩进,但我没有任何运气让它工作。任何帮助都将不胜感激。
import calendar
cal = calendar.Calendar()
for year in range(2015,2016):
for month in range(1,13):
monthdays = [d for d in cal.itermonthdays(year
这是我的终端回答后,快速运行命令。
Traceback (most recent call last):
File "bin/browser", line 35, in import browser
File "/home/alen/browser/browser/init.py", line 12, in from browser import BrowserWindow
File "/home/alen/browser/browser/BrowserWindow.py", line 32
self.refreshbutton = self.b
if len(trashed_files) == 0 :
print "No files trashed from current dir ('%s')" % os.path.realpath(os.curdir)
else :
index=raw_input("What file to restore [0..%d]: " % (len(trashed_files)-1))
if index == "*" :
for tfile in trashed_files :
这是代码
GrassFilledX = GrassGenX
GrassFilledY = GrassGenY
GrassFillL = True
while GrassFillL == True:
if gx == hgx or hgx2:
while not crashed:
错误显示
while not crashed:
^
IndentationError: expected an indented block
我试着用“美丽汤”编写一个简单的脚本,它可以只需要两个信息,并且可以从一个网站生成一个SQL文件。
import mechanize
import urlparse
from bs4 import BeautifulSoup
op = mechanize.Browser()
op.open("https://www.mentalhelp.net/symptoms/")
for link in op.links():
print link.text
print urlparse.urljoin(link.base_url, link.url)
get = BeautifulSo
我得到以下缩进错误
>>> number = 35
>>> if number == 35:
print 'true'
else:
File "<pyshell#130>", line 3
else:
^
IndentationError: unindent does not match any outer indentation level
>>>
这只会在空闲时发生,而不会发生在命令行上。我在Windows XP上使用Python 2.6.4。我已经在
>>> if 5==5:
print '5'
else: print 'cat'
File "<pyshell#2>", line 3
else: print 'cat'
^
IndentationError: unindent does not match any outer indentation level
无论缩进是什么,它仍然不起作用。即使我尝试将print cat语句放在下一行,也会出现语法错误。为什么会这样呢?
我创建了名为resource.py的Python3模块,其中包含两个函数,Read_Cursor和Write_Cursor。当我导入模块时,会得到一个错误,这取决于我导入模块的方式。
我试过:
import resource
from resource import *
Read_Cursor=resource.Read_Cursor
resource.py:
def Write_Cursor(Cursor):
with open("/run/thermostat/Cursor","w") as f: # Set the Cursor posit
我不太明白下面代码的问题是什么
for stripe in [sku.value for sku in model_sheet.col(13) if str(sku.value)]:
try:
stripe = int(stripe)
except ValueError:
stripe = unicode(stripe)
for stars in [sku.value for sku in model_sheet.col(19) if str(sku.value)]:
yield HatI
这是我的密码
def count (a, e, i, o, u):
a_length = len(a);
e_length = len (e);
i_length = len (i);
o_length = len (o);
u_length = len (u);
total = 0;
for i in range (a_lenght):
if(a[i] == u[0]):
end = i + u_length;
if (a[i:end] == u):
total +=1
我正在遵循Michael Halls-Moore算法交易一书,并对代码有一些问题。当我将代码粘贴到python中时,我得到了一堆错误。
我是不是遗漏了什么,因为它和书中写的一模一样?
from __future__ import print_function
from numpy import cumsum, log, polyfit, sqrt, std, subtract
from numpy.random import randn
def hurst(ts):
"""Returns the Hurst Exponent of the time ser
我做了一个小程序来学习这个基础,我不明白为什么它不能工作,所以你能帮我解释一下我的错误吗?欢迎每一个答案
import random
def gessing_game():
t = 0
r = random.randint(0,100)
print(r)
y = int(input("Please choose your number"))
while y != r:
t = t + 1
print("You have made",t,"attempts")
if y > r:
print("T
我找到了一个max_value (灰度2D数组50,200)
max = numpy.amax(matrice)
所以它给了我一个值。现在我想知道我是否能找到这个值。我试过这段代码:
for x in range (1,50):
for y in range (1,200):
if matrice[x,y]==max:
print ("[%s,%s]",x,y)
但它给了我一条错误消息:
“对于范围内的y (1,200):IndentationError:应为缩进块”
谁能告诉我错误是什么,或者我怎样才能找到这个像素的地址?
我是python的初学者,在学习过程中,在执行if语句时遇到了一个错误。
有人能告诉我我在代码中遗漏了什么吗?
文件"Demo_class2_Conditions.py",第8行
打印(X)
^
IndentationError:期望有一个缩进块
X=int(input('Enter the value of X:'))
Y=int(input('Enter the value of Y:'))
Z=int(input('Enter the value of Z:'))
if X > Y:
if X >
设置
我在每个城市都刮住房广告,用Scrapy。在每个城市,我创建了一只蜘蛛,在需要的时候,我会调整(一点点)到每个城市。
问题
我把来自城市A的代码复制到一个.py文件中,目的是刮城市B。我以前做过很多次了。现在,我收到了代码中以下几行的IndentationError,
pl=[]
for key, value in df['postal'].iteritems():
temp = value
pl.append(str(temp))
错误是针对temp和状态IndentationError: expected an indented block。
当我尝试与两个数字相乘时,在jupyter中得到了低于错误的值。 import tensorflow as tf
tf.executing_eagerly()
x = tf.constant(2)
y = tf.constant(3)
multi = x*y
with tf.Session() as sess:
print(sess.run(multi))
## error
File "<ipython-input-35-755ab78de6c6>", line 5
print(sess.run(multi))
^
Indentation
我的缩进有什么问题?
>>> try:
print("Hello World!")
except:
File "<pyshell#2>", line 3
except:
^
IndentationError: unindent does not match any outer indentation level
使用空闲的Python 2.7.2,Shell;在try语句之后,我尝试退格到适当的缩进,但它转到了左边距,我必须键入4个空格。
我试图编写一个登录页面,Visual说第5行有IndentationError: expected an indented block,我能做些什么来修复这个函数呢?我可以这样编码登录页面吗?
这只是为了我的练习,我是一个新的编码器。
def register_acc(x,y,z):
while True:
x = input("Enter nickname: \t")
if x.isalnum == True:
while True:
y = char(input("enter pass: \t")