0
Hey guys got a question for you!
See this is my code below, help me out in such a way that i make this code as an input.... For example: I would like to ask is it a hot day? If the reader answers true he gets the answer it's a hot day, drink plenty of water, same thing if it was a false.... Then it's a cold day........ Well here is my code: is_hot= True is_cold= False if is_hot : print('Its a hot day') print('Drink plenty of water') elif is_cold : print('Its a cold day') print('Wear warm clothes') else: print('Have a nice day! ')
5 odpowiedzi
+ 3
is_hot= input("is hot today (enter yes or no):\n")
if is_hot.lower() == "yes" :
print('Its a hot day')
print('Drink plenty of water')
else :
print('Its a cold day')
print('Wear warm clothes')
print('\nHave a nice day! ')
+ 6
Sandra Meyer Since the assigned value results in boolean, the ternary isn't needed:
is_cold = input().lower() in [ "yes", "y", "true", "1" ];
+ 2
Little more generic:
is_cold = True if input().lower() in [ "yes", "y", "true", "1" ] else False;
Edit, shorter generic:
is_cold = input().lower() in [ "yes", "y", "true", "1" ];
+ 1
True David Carroll 😁 thx
0
Thanks jayakrishna