+ 2
[Solved] Can anyone explain me why is this code giving error?
Learning property decorator for the first time I don't quite understand why it is giving error on line 4 and line 26 Here's my code: https://code.sololearn.com/clAlr934O4lq/?ref=app.. I understand now.. there was a problem using the property decorator before.. and maybe I somehow didn't write the full code.. Here's the solution I found it online https://code.sololearn.com/c5DMKz8LPsN3/?ref=app thanks everyone for helping me.. đ
6 Answers
+ 7
Moon ,
maybe the use of try... exept can help:
@temperature.setter
def temperature(self, value):
print("Setting value...")
try:
if value < -273.15:
raise ValueError("Temperature below -273 is not possible")
self._temperature = value
except ValueError as v_e:
print(v_e)
+ 4
Moon ,
i have used your code and have applied the modifications with try... except. it should run, just try it.
https://code.sololearn.com/cDKnZ9bQ91JS/?ref=app
+ 3
People can help you quicker when you put your code in a script on sololearn playground:
Go to Code section, click +, select the programming language, insert your code, save. Come back to this thread, click +, Insert Code, sort for My Code Bits, select your code.
This way, it is much better readable and other can test your code.
+ 2
It is giving the error because you programmed it to raise an error when one tries to input an invalid temperature value. :)
+ 1
last line for what? if you delete it your code will work fine.
+ 1
Lothar, I tried it.. it shows syntax error.. and if I remove the raise error part it shows no output đ