Answer the question
In order to leave comments, you need to log in
How to count the elements of a list in the desired numerical range?
Task:
Create a function comfort_count(temperatures) to count comfortable days in the passed list — days with air temperature from 22 to 26 degrees inclusive.
As a result of the function, the function should display the string 'Number of comfortable days this month: N', where N is the result of the calculation in the loop with the condition. First, count the comfortable days in May 2017, and then in May 2018.
The code:
may_2017 = [24, 26, 15, 10, 15, 19, 10, 1, 4, 7, 7, 7, 12, 14, 17, 8, 9, 19, 21, 22, 11, 15, 19, 23, 15, 21, 16, 13, 25, 17, 19]
may_2018 = [20, 27, 23, 18, 24, 16, 20, 24, 18, 15, 19, 25, 24, 26, 19, 24, 25, 21, 17, 11, 20, 21, 22, 23, 18, 20, 23, 18, 22, 23, 11]
def comfort_count(temperatures):
temp = len(temperatures)
for temp in temperatures:
if 22 <= temp <= 26:
temp += 1
print('Количество комфортных дней в этом месяце: ', temp)
comfort_count(may_2017)
comfort_count(may_2018)
Answer the question
In order to leave comments, you need to log in
No need to use temp for counting days and for iterating.
count = 0
for t in temperatures:
if t <= 26:
count += 1
The loop variable overwrites the variable in the same scope.
def comfort_count(temperatures):
print('Количество комфортных дней в этом месяце: ', len([x for x in temperatures if x <= 26 and x >= 22]))
Here's what helped me, insert this meta tag into the header of the site
<meta name="viewport" content="width=device-width, initial-scale=1">
as a rule, such difficulties arise when the specificity of such an appeal to selectors is not taken into account. try throwing these properties at the end of the css file.
Without getting into the details of the specific problem, there are a few steps to identifying the error:
@media all and (min-width: 640px) and (max-width: 734px){
* {
background: red;
}
}
I tried to apply resolution
and device-width
attached the scaling of the whole body to them. Applied @media screen
and @media all
connected the tag viewport
. I'm testing on a netbook and nothing works.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question