Error : IndentationError: unexpected indent
Error : IndentationError: unexpected indent
我是 python 的新手,所以当 运行 我的代码基于 类 和对象时,我得到了这个错误:IndentationError: unexpected indent
但不知道我哪里出错了
请帮助我得到它以及如何解决它
感谢你在期待....
祝你今天过得愉快! :>
class Get_started:
def __init__(self,name):
self.name = str(input('Enter name'))
print('Hello ',self.name)
self.rect = self.Rectangle()
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)
m1 = Get_started('mr_halkat')
m1.Rectangle.get_lb()
m1.Rectangle.show()
m1.Rectangle.cal_area()
您需要缩进 Rectangle
class 中的所有内容,并减少 cal_area
方法中 print
语句的缩进。
修改后的代码如下:
#!/usr/bin/python
class Get_started:
def __init__(self,name):
self.name = str(input('Enter name'))
print('Hello ',self.name)
self.rect = self.Rectangle()
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)
m1 = Get_started('mr_halkat')
m1.Rectangle.get_lb()
m1.Rectangle.show()
m1.Rectangle.cal_area()
说class Rectangle
里面没有函数,cal_area(self)
函数里面缩进错了
您是否尝试过这样放置代码:
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)
我是 python 的新手,所以当 运行 我的代码基于 类 和对象时,我得到了这个错误:IndentationError: unexpected indent 但不知道我哪里出错了 请帮助我得到它以及如何解决它 感谢你在期待.... 祝你今天过得愉快! :>
class Get_started:
def __init__(self,name):
self.name = str(input('Enter name'))
print('Hello ',self.name)
self.rect = self.Rectangle()
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)
m1 = Get_started('mr_halkat')
m1.Rectangle.get_lb()
m1.Rectangle.show()
m1.Rectangle.cal_area()
您需要缩进 Rectangle
class 中的所有内容,并减少 cal_area
方法中 print
语句的缩进。
修改后的代码如下:
#!/usr/bin/python
class Get_started:
def __init__(self,name):
self.name = str(input('Enter name'))
print('Hello ',self.name)
self.rect = self.Rectangle()
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)
m1 = Get_started('mr_halkat')
m1.Rectangle.get_lb()
m1.Rectangle.show()
m1.Rectangle.cal_area()
说class Rectangle
里面没有函数,cal_area(self)
函数里面缩进错了
您是否尝试过这样放置代码:
class Rectangle:
def __init__(self):
print('In this program we are gonna calculate the area of rectange')
def get_lb(self,l,b):
self.l = int(input('Enter length : '))
self.b = int(input('Enter breadth : '))
def show():
print('Length & Breadth of rectangle are ',self.l,' & ',self.b)
def cal_area(self):
self.area = self.l * self.b
print('Area : ',self.area)