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

29th Sep 2018, 11:25 PM
Potato Hacker
Potato Hacker - avatar
6 Réponses
+ 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.
29th Sep 2018, 11:43 PM
Faisal
Faisal - avatar
+ 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).
10th Oct 2018, 12:26 AM
Faisal
Faisal - avatar
+ 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
30th Sep 2018, 3:07 PM
Potato Hacker
Potato Hacker - avatar
+ 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.
30th Sep 2018, 3:17 PM
Faisal
Faisal - avatar
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
29th Sep 2018, 11:50 PM
Ulisses Cruz
Ulisses Cruz - avatar
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
7th Oct 2018, 6:40 PM
Potato Hacker
Potato Hacker - avatar