# Average night’s sleep survey

For 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:

This algorithm is based on:

#### 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:

Write a new program to make suitable recommendations to school children on whether or not they are spending enough time sleeping per night. Your program should:

• Ask for the name and the age of the end-user,
• Ask for the number of hours they spend sleeping each night (on average),
• Compare this number of hours with the recommended hours for their age category,
• Display an approriate message to say whether:
• They are not spending enough time sleeping per night,
• They are spending the recommended amount of time sleeping per night,
• They are spending more than the recommended amount of time sleeping per night!

Your algorithm will be based on:

As a reminder, 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

#### Testing

Create a test plan to test your program. Make sure to include valid, boundary, invalid and erroneous test data in your test plan: (click on the … to add your own data)

 Test # Input Values: Type of test Expected Output Actual Output #1 Age: 12Number of Hours: 10 Valid Test You are spending the recommended amount of time sleeping per night. #2 Age: …Number of Hours: … Valid Test … #3 Age: …Number of Hours: … Invalid Test … #4 Age: …Number of Hours: … Invalid Test … #5 Age: …Number of Hours: … Boundary Test … #6 Age: …Number of Hours: … Boundary Test … #7 Age: …Number of Hours: … Erroneous Test … #8 Age: …Number of Hours: … Erroneous Test …

Did you like this challenge?

Click on a star to rate it!

Average rating 3.5 / 5. Vote count: 16

No votes so far! Be the first to rate this post.

As you found this challenge interesting...