Hint: Use loop to solve the problem
def q4_func ( data , day_one) :
Example 4.1: illustrates the requirements for the function. We
assume that the following inputs are
The function's input is a one-dimensional grid of values, all of
the same type int showing the temperature of consecutive days, and
the first representing the date corresponding to the first value in
the data array. A date is represented by an integer value from 1 to
7. For example, 1 represents Monday, 7 represents Sunday, or 2
represents Tuesday. Imagine that day_one is an integer value from 1
to 7 (inclusive).
1. The function identifies whole weeks where temperatures
increase or remain the same over the consecutive weekdays and
returns the number of such weeks. The function only considers a
week when temperature values for all seven days are available (day
1 to 7), otherwise, that week is ignored. The weekdays are defined
as 1 to 5 (Monday to Friday). The weekend days are defined as 6 to
7 or (Saturday to Sunday). In the example 4.1 above, the first day
represent saturday corresponding to 6, the first index begin at
index 2 (values 21).
2. Week 1 is represented by temperature values 21, 23, ... 22 .
The weekdays are from monday to friday showing the first 5 values
21, ... 24. This week is not selected because the temperature
values for consecutive days of the week do not remain the same or
rise.
3. In the second week, temperature measurements 21, 23, 23,
25, 26, 24, and 23. The days of the week are Monday to Friday,
representing the first five. Values 21, 23, 23, 25, and 26. This
week's consecutive weekdays, This week is selected because the
temperature readings are the same or higher.
4. Similarly, the third week of weekdays 22, 23, 24, 26,
and 28 is chosen. The last three values do not represent a week
and are ignored. Represents a value from Monday to Wednesday.
5. The final three values are ignored because they do not
represent a whole week, they only
represent values from Monday to Wednesday.
6. The function will return 2, indicating two whole weeks
where temperatures rise or remain the same over the consecutive
days of the week.
data - [23, 26, 21, 23, 25, 26, 24, 26, 22, 21, 23, 23, 25, 26, 24, 23, 22, 23, 24, 26, 28, 27, 30, 29, 29, 27]
Hint: Use loop to solve the problem def q4_func ( data , day_one) : Example 4.1: illustrates the requirements for the fu
-
answerhappygod
- Site Admin
- Posts: 899604
- Joined: Mon Aug 02, 2021 8:13 am
Hint: Use loop to solve the problem def q4_func ( data , day_one) : Example 4.1: illustrates the requirements for the fu
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!