A “sleep debt” represents the difference between a
person’s desirable and actual amount of sleep. Write a program that
prompts the user to enter how many hours they slept each day over a
period of 5 days.
Using 8 hours per day as the desirable amount of sleep, determine
their sleep debt by calculating the total number of hours of sleep
they got over the five-day period and subtracting that from the
total hours of sleep they should have got.
If the user has a sleep debt display a message saying they need
more sleep. If the user does not have a sleep debt, display a
message expressing your jealousy.
Sample output: (user inputs in red)
This program will calculate your sleep-debt over 5 days.
Please enter Day 1 sleep:
6
Please enter Day 2 sleep:
7
Please enter Day 3 sleep:
8
Please enter Day 4 sleep:
7
Please enter Day 5 sleep:
6
Your total hours of sleep were:
34
Your sleep debt over this time is:
6 hours
You need more sleep!
(Could you write in Python format)
#Python program that calculate the sleep debt. #This python program that prompts user to enter the days sleep for each day. #Then find the sleep debt . #sleepdebt.py def main(): #Set variables ACTUAL_SLEEP = 40 #actual sleep total_sleep = 0 #To get user sleep for a day print('This program will calculate your sleep-debt over 5 days.') #run for loop for 5 days for day in range(0,5): print('Please enter Day', day+1, ' sleep:') user_sleep=int(input()) #add sleep to total sleep total_sleep=total_sleep+user_sleep #find the sleep debt sleep_debt=ACTUAL_SLEEP-total_sleep #check if sleep_date is more than 0 if sleep_debt>0: print('Your sleep debt over this time is:') #print sleep_debt print(sleep_debt) print('You need more sleep!') else: print('You are healthy.!') #calling main method main()
Sample Output:
Sample run1:
This program will calculate your sleep-debt over 5
days.
Please enter Day 1 sleep:
6
Please enter Day 2 sleep:
7
Please enter Day 3 sleep:
8
Please enter Day 4 sleep:
7
Please enter Day 5 sleep:
6
Your sleep debt over this time is:
6
You need more sleep!
Sample run2:
This program will calculate your sleep-debt over 5
days.
Please enter Day 1 sleep:
8
Please enter Day 2 sleep:
8
Please enter Day 3 sleep:
8
Please enter Day 4 sleep:
8
Please enter Day 5 sleep:
8
You are healthy.!
Get Answers For Free
Most questions answered within 1 hours.