Python 缩进错误和其他错误
我对python非常陌生,我正在为adidas.com编写一个自动URLGen,我遇到了多个与IndentationError有关的错误:意外的缩进,缩进块中应该出现,操作符周围应该出现空白。然而,我从一个已经制作好的URLGen复制了这段代码 快速格式化 代码应根据范围缩进:Python 缩进错误和其他错误,python,Python,我对python非常陌生,我正在为adidas.com编写一个自动URLGen,我遇到了多个与IndentationError有关的错误:意外的缩进,缩进块中应该出现,操作符周围应该出现空白。然而,我从一个已经制作好的URLGen复制了这段代码 快速格式化 代码应根据范围缩进: def URLGen(Model. size): BaseSize = 500 # BaseSize is for shoe size 6.5 ShoeSize = 6.5 ShoeSize = ShoeSize - 6
def URLGen(Model. size):
BaseSize = 500
# BaseSize is for shoe size 6.5
ShoeSize = 6.5
ShoeSize = ShoeSize - 6.5
ShoeSize = ShoeSize x 20
RawSize = ShoeSize + int(RawSize)
URL = https://www.adidas.com/us/ + str(model) + '.html?forceSelSize=' +
str(model) + str(ShoeSizeCode)
return URL
Model = raw_input('Model #')
Size = input('Size: ')
URL = URLGen(Model. size)
print (str(URL))
您可以找到缩进规则
其他错误
您还存在其他各种错误:
函数调用和定义
及
Python使用,
来分隔变量,而不是像您使用的
未正确创建或使用变量
这里您使用RawSize=ShoeSize+int(RawSize)
但是int(RawSize)
不包含任何内容RawSize
这里您使用URL=https://www.adidas.com/us/ +str(model)+'.html?forceSelSize='+str(model)+str(ShoeSizeCode)
,但是您声明了model
,因此model
不存在,model
就是不存在ShoeSizeCode
如果您打算用python编码,我建议您首先阅读如何正确使用它,然后自己尝试,而不是仅仅复制粘贴您认为可以工作的代码。您复制的代码确实存在缩进问题。函数的内容应该缩进4个空格。在python中,缩进并不重要,函数中的任何内容都必须缩进以标记范围
def URLGen(model, size):
BaseSize = 500
# BaseSize is for shoe size 6.5
ShoeSize = 6.5
ShoeSize = ShoeSize - 6.5 # this gives 0
ShoeSize = ShoeSize x 20 # this gives 0
RawSize = ShoeSize + int(RawSize) # Rawsize is not a number
URL = 'https://www.adidas.com/us/' + str(model) + '.html?forceSelSize=' + str(model) + str(ShoeSizeCode) # SHoeSizeCode does not exits
return URL
Model = raw_input('Model #')
Size = input('Size: ')
URL = URLGen(Model, size)
print(str(URL))
def URLGen(Model. size):
URL = URLGen(Model. size)