0

Python support

Please can someone familiar with Python help with this: The squirrels in Palo Alto spend most of the day playing. In particular, they play if the temperature is between 60 and 90 (inclusive). Unless it is summer, then the upper limit is 100 instead of 90. Given an int temperature and a boolean 'is_summer', return True if the squirrels play and False otherwise The above is a question that basically requires me to create a function that takes two arguments: temperature in value(int) and a Boolean as the other. The function is expected to return False Only when the integer value falls outside the range 60-90 and the Boolean argument is False. However, if the Boolean value is true then the upper limit of the range is extended to 100. Every other case should return false. Please I need support on this cause I'm relatively new to programming and have tried to resolve the problem but failed. Anybody?

15th Feb 2019, 1:56 AM
Chimezie Azih
5 ответов
+ 5
The "while" loop is not necessary. I can see your train of thought, but adjust it slightly to something like this: def squirrel_play(temp, is_summer): if is_summer: return 60 <= temp <= 100 else: return 60 <= temp <= 90 I think this will be the result you are looking for. However there are many ways to achieve the same result. def squirrel_play(temp, is_summer): if is_summer is True and temp<=100 and temp>=60: return True elif is_summer is False and temp<=90 and temp>=60: return True else: return False Just take your time and think about what the question is asking... def squirrel_play(temp, is_summer): if is_summer and temp in range(60,101): return True elif not is_summer and temp in range(60,91): return True else: return False
15th Feb 2019, 2:54 AM
Steven M
Steven M - avatar
+ 8
The solutions provided by Steven M are absolutely correct. The last solution provided by him is most easy to understand.
15th Feb 2019, 3:12 AM
Arushi Singhania
Arushi Singhania - avatar
+ 4
So, try to solve it first by yourself. You have mentioned the full algorithm. Try to implement it. If you have any problem, then ask. # First take two inputs, first an integer and second a Boolean. #You can declare function like def func(temperature,is_summer) #Write data of Ur function. #Use if else condition inside function and return two different values based on your condition. Try to implement it. If you face any problem, then ask. We will surely help u.
15th Feb 2019, 2:02 AM
Arushi Singhania
Arushi Singhania - avatar
+ 1
Thanks all. I'm really grateful
15th Feb 2019, 10:32 AM
Chimezie Azih
0
Thanks @Arushi . Like I initially stated, I've already tried the best possible way I could on my own to answer the question. Wouldn't be asking here If I knew I could answer it correctly. I, however, seem to be missing something. As it does seem like my proffered answer does not cover all the possible cases of the problem. I'll drop my proffered answer here. def squirrel_play(temp, is_summer): while not is_summer: if temp == range(60,91): return is_summer else: return False while is_summer: if temp == range(60,101): return True else: return False Is it correct?
15th Feb 2019, 2:13 AM
Chimezie Azih