0

# Why?!

Look at my code...its saying for any temp greater than or equal to 0 is colder than absolute 0. how is that possible? if a number is greater than 0 it would be hotter than absolute 0 right? so why isnt it (temperature <= 0) ??? https://code.sololearn.com/ceMoxC5M8uHi/?ref=app

6th Apr 2017, 3:23 PM
Seth T
+ 6
By using assert you automatically raise an exception anytime its condition is False. And so, it will terminate your program. If you want to enforce using only a positive value, you should either use a loop which breaks only if the argument is positive (a good option to validate user input) or cast a try/except block and catch the exception before it terminates your program (I think the best solution in this case). In any case, you can print a respective message to the user, why the function did not work.
6th Apr 2017, 3:52 PM
Kuba SiekierzyĆski
+ 5
It does put an error only in the last case, which is true, as -5 is definitely not greater or equal zero. 32.0 451 Traceback...
6th Apr 2017, 3:42 PM
Kuba SiekierzyĆski
+ 1
change >= to <=
6th Apr 2017, 3:27 PM
Edward
0
nooo, see if i do that then when 273 is ran through it causes it to assert and claims its colder than absolute 0
6th Apr 2017, 3:29 PM
Seth T
0
exactly. when using assert isnt it basically if then? if (temp <= 0) print(Colder than absolute 0) because if its saying that then correct -5 isnt greater than 0 so why would it assert?
6th Apr 2017, 3:45 PM
Seth T
0
ohhhh im dumb, so assert will only raise if the argument in the assert line is NOT met. so like 1 = runs through -2 - program checks through assertion and verifies it is NOT equal or greater than 0 so therefore its less than absolute 0 which is impossible. thanks sm i think i get it now, always nice to make sure you really understand a function
6th Apr 2017, 3:56 PM
Seth T