When i run this code, i am am not getting any output when i punch in the available input

Viewed 18

Here is a code to take boolean input in the form of 'H' & 'C' and print the output accordingly using if-else statement. When I run this code, I am able to enter the input but I am not getting any output after entering 'H' or 'C'. Where am I going wrong?

Error message: No error message.

Expected result: On Entering 'H' - 'Its a hot day'; On Entering 'C' - 'Its a cold day'.

H = True
C = False

print("Enter if it is a hot or cold day \n , H for Hot day, C for Cold day")

i = input('enter H or C \n')


if (i == H):
   print('Its a hot day')

elif (i == C):
   print('Its a cold day')
1 Answers

You are setting H and C as True and False. Then you are comparing the input (which should be either the string "H" or the string "C") to these boolean values. They will never be equal. Instead, check if the input is either of these strings:

H = "H"
C = "C"
print("Enter if it is a hot or cold day \n , H for Hot day, C for Cold day")
i = input('enter H or C \n')
if (i == H): 
  print('Its a hot day')
elif (i == C): 
  print('Its a cold day')
Related