0
Whats the problem With this python Code?
Here's The Code: class Programmer: def __init__(self, web): self.web = web def WEB(self): print("i'm a website developer") WEB = Programmer("HTML, CSS, JS") print(WEB) WEB.web This is what it is saying on output: File "..\Playground\", line 2 def __init__(self, web): ^ IndentationError: expected an indented block
6 Answers
+ 2
Because Python doesn't use curly brackets for its conditionals, loops, etc., it requires that you use indentation for any code within that specific block. As classes also need to have code within them, you would need to indent all the code after the declaration of the class to specify that that section is apart of the class rather than just separate code.
+ 2
H4CK3RđșđșC4tđșđș As the spacing generally for operators (e.g. +, +=, ==, etc.) don't matter in Python, the first code was fine for that aspect. What I meant was the space at the beginning of lines 7 and 8 (a single space was left before the start of each of those lines, which confused the program and though it was supposed to be an indent).
+ 1
your code Ulisses Cruz
is this:
class Programmer:
def __init__(self, web):
self.web = web
def web(self):
print("i'm a website developer")
WEB = Programmer("HTML, CSS, JS")
print(WEB)
WEB.web
this is the error it's saying:
File "..\Playground\", line 7
WEB = Programmer("HTML, CSS, JS")
^
IndentationError: unindent does not match any outer indentation level
+ 1
H4CK3RđșđșC4tđșđș It seems that a space was left in front of the lines WEB = Programmer(... and print(WEB), so just getting rid of that space fixes the problem.
0
Here is the code with proper indentation and method name corrected:
class Programmer:
def __init__(self, web):
self.web = web
def web(self):
print("i'm a website developer")
WEB = Programmer("HTML, CSS, JS")
print(WEB)
WEB.web
0
class Programmer:
def __init__(self, web):
self.web = web
def web(self):
print("i'm a website developer")
WEB =Programmer ("HTML, CSS, JS")
print(WEB)
WEB.web
was this what u mean?
@Faisal