Average night’s sleep survey

sleep-surveyFor her PSHE homework on the importance of sleep, Clarisse has decided to collect data from pupils of different year groups from her school. She will do so using a short survey.

The aim of the survey will be to find out, on average, how many hours of sleep students have per night and to compare these findings with the recommended number of hours for high school students.

According to the National Sleep Foundation, the recommended numbers of hours of sleep per night are as follows:

Age Group Recommended Sleep
School-aged Children 6-13 years 9 to 11 hours
Teenagers 14-17 years 8 to 10 hours
Young Adults 18-25 years 7 to 9 hours

Clarisse’s survey will only have one question: How many hours do you sleep each night?

To help her calculate the resulting average number of hours of sleep per night she would like you to write a Python program based on the following flowchart:
sleep-survey-flowchart

Algorithm Trace Table

To gain a better understanding of how this algorithm works you will need to complete the following trace table considering the following user inputs:

8 , y , 10 , y , 12 , n

 Line NumbercarryOntotalHoursnumberOfStudentscarryOn ==”y”hoursaverageOUTPUT
1“y”
20
30
4True
58
68
71
88
98
10“y”
4True
510
618

Python Code

Use the above flowchart to complete the Python code for this program:

Share Button
Tagged with: , ,