+ 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")
15 Respuestas
+ 1
Don't worry it's a bug, your code works perfectly!
+ 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!")
+ 3
How to learn python bro?
+ 2
Oh thanks man
+ 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.
+ 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')
+ 1
No problem have a good day
+ 1
your probably not entering the inputs right for sololearn
i would get rid of that first line
+ 1
Ok . Brother!
+ 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')
+ 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')
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)
0
Do the interduction to python course go in my profile its the only course i do now
0
how to do that so?