Hey guys got a question for you! | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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! ')

1st Aug 2020, 2:49 PM
Mehul sathish
Mehul sathish - avatar
5 Answers
+ 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! ')
1st Aug 2020, 3:05 PM
Jayakrishna 🇮🇳
+ 6
Sandra Meyer Since the assigned value results in boolean, the ternary isn't needed: is_cold = input().lower() in [ "yes", "y", "true", "1" ];
1st Aug 2020, 3:08 PM
David Carroll
David Carroll - avatar
+ 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" ];
1st Aug 2020, 3:03 PM
Sandra Meyer
Sandra Meyer - avatar
+ 1
True David Carroll 😁 thx
1st Aug 2020, 3:09 PM
Sandra Meyer
Sandra Meyer - avatar
0
Thanks jayakrishna
1st Aug 2020, 3:06 PM
Mehul sathish
Mehul sathish - avatar