+ 2

Why doesnt it work

I wanted to make a code because im a beginner everything works except elif when i put 36 it has no output temperature = input() temperature_1 = int(input()) if temperature_1 > 39: print("hot") elif temperature_1 == 36: print("normal") else: print("cold")

18th Aug 2024, 12:34 AM
Pavlos Tsakakis
Pavlos Tsakakis - avatar
15 Respuestas
+ 1
Don't worry it's a bug, your code works perfectly!
18th Aug 2024, 12:43 AM
Creator75
Creator75 - avatar
+ 3
Yea i made a diffrent code where i have those possibilities temperature_1 = int(input()) if temperature_1 >= 37: print("hot") elif temperature_1 == 36: print("normal") else: print("cold") print("Task Complete!")
18th Aug 2024, 11:33 AM
Pavlos Tsakakis
Pavlos Tsakakis - avatar
+ 3
How to learn python bro?
18th Aug 2024, 4:26 PM
Obsumaafi Obsa
Obsumaafi Obsa - avatar
+ 2
Oh thanks man
18th Aug 2024, 12:45 AM
Pavlos Tsakakis
Pavlos Tsakakis - avatar
+ 2
Did you not consider where the temperature was between 36 ~ 39 (inclusive)? there's no branch for handling that possibility, Where such input was given, there'd be an unexpected output. elif temperature_1 >= 36: # <- 36 ~ 39 handled here In short, 36 ~ 39 degrees shouldn't fall into "cold" category.
18th Aug 2024, 11:13 AM
Ipang
+ 2
To fix your code you should add less than or equals operator(<=) to your elif condition. Fixed code fragment: elif temperature_1 <= 36: I also suggest avoiding hardcoded values in conditional operators to prevent confusion and improve code readability. In this regard you can optimize your code by creating bool variables in the head of your code. Improved code: int temperature = int(input()) hot = temperature > 39 normal = temperature <= 36 cold = temperature < 36 if hot: print('hot') elif cold: print('cold') elif normal: print('normal')
21st Aug 2024, 6:36 PM
Lazy Dev
Lazy Dev - avatar
+ 1
No problem have a good day
18th Aug 2024, 12:46 AM
Creator75
Creator75 - avatar
+ 1
your probably not entering the inputs right for sololearn i would get rid of that first line
18th Aug 2024, 4:38 AM
Junior
Junior - avatar
+ 1
Ok . Brother!
18th Aug 2024, 4:34 PM
Obsumaafi Obsa
Obsumaafi Obsa - avatar
+ 1
perhaps you only need the normal temperature. t = int(input()) normal = 36 if t > normal: print('hot') elif t < normal: print('cold') else: print('normal') # two liner alternative(put the input and logic inside print): normal = 36 print('hot' if (tmp:=int(input())) > normal else 'cold' if tmp< normal else 'normal')
22nd Aug 2024, 2:42 AM
Bob_Li
Bob_Li - avatar
+ 1
or maybe if your normal temperature is a range of values, say 35 to 37 is considered normal, perhaps something like: #if 35,36,37 is considered normal n_min = 35 n_max = 37 print('hot' if (t:=int(input()))>n_max else 'cold' if t<n_min else 'normal')
22nd Aug 2024, 3:07 AM
Bob_Li
Bob_Li - avatar
0
do you need the first line? maybe you should delete it. or maybe the second line was supposed to be temperature _1 = int(temperature)
18th Aug 2024, 2:44 AM
Bob_Li
Bob_Li - avatar
0
Do the interduction to python course go in my profile its the only course i do now
18th Aug 2024, 4:26 PM
Pavlos Tsakakis
Pavlos Tsakakis - avatar
0
how to do that so?
19th Aug 2024, 12:10 AM
vrie hyx
vrie hyx - avatar