1
What’s wrong with this code? Compiler points error on line 8...
class Pai(object):
Nome='Carlos'
Sobrenome='Maria'
Residencia='Rio de Janeiro'
class Filha(Pai):
Nome='Luciana'
def __init__(self, humor):
self.humor = humor
f = Filha('alegre')
print(f.Nome)
print(Nome.Pai)
print(f.Sobrenome)
print(f.Residencia)
print(f.olho)
What error is being presented? Is it compile error (type, syntax error or something like that) or execution error (incorrect result, exception, etc)? There are several problems with your code - for example, in
print(Nome.Pai)
- but to help you better it would be nice to know exactly what the compiler is complaining about.– mgibsonbr
The error is this: expected an indented block
– ProgramadorLendario
I’m learning Oop in python now I came from C and get lost in Oop but I see for help
– ProgramadorLendario
By any chance are you mixing spaces with tabs? The syntax of the code posted seems correct, there is no reason to give this error. I suggest checking before each codeline identada if the number of spaces/tabs is correct. Separating the upper class from the lower class by a blank line is also good (although I think that has nothing to do with the mistake).
– mgibsonbr
The error is probably the same edentation, many beginners in python make that mistake, and line 12 would also be wrong for
Nome
not be defined.– Brumazzi DB
I’ll check but thanks for your help...
– ProgramadorLendario
When you have an error, paste the error message - Python says which is the error if you read the message carefully, in addition to the line number. Now - to see here you’re right - can be really mixing spaces with tabs - configure your text editor to use 4 spaces in the indentation, never "tab"(which is a different character than space)
– jsbueno
Another thing -I think you’re getting caught up in your understanding of OO there- anything, have contact Inbox in my profile.
– jsbueno