Question

A “sleep debt” represents the difference between a person’s desirable and actual amount of sleep. Write...

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)

Homework Answers

Answer #1
#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.!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Days of the week Write a program that asks the user for a number in the...
Days of the week Write a program that asks the user for a number in the range of 1 through 7. The program should display the corresponding day of the week, where 1 = Monday, 2 = Tuesday, 3 = Wednesday, 4 = Thursday, 5 = Friday, 6 = Saturday, and 7 = Sunday. The program should display an error message if the user enters a number that is outside of the range of 1 though 7.
Write a program in python that calculates the salary of employees. The program should prompt the...
Write a program in python that calculates the salary of employees. The program should prompt the user to enter hourly rate and number of hours of work a day. Then, the program should display the salary daily, bi-weekly (5 days a week), and monthly. Sample program: Enter your hourly rate: >>> 20 Enter how many hours you work a day: >>> 8 Your daily salary is: $160 Your bi-weekly salary is: $1600 Your monthly: $3200
Write a program (C language) that will read the number of a month and will print...
Write a program (C language) that will read the number of a month and will print the number of days in the month. Ignore leap years. Use 28 days for February. Have the program runs in a continuous loop, allowing the user to enter a month number, see that number of days, and repeat. Use month number = 0 to exit the loop and the program. Program must meet the following criteria: 1.Your name and the name of the program...
How much money do you think you would earn in a period of 30 days if...
How much money do you think you would earn in a period of 30 days if you were paid as follows: one cent for the first day, two cents for the second day, four cents for the third day, eight cents for the fourth day, and so on (i.e. your salary doubles each day)? Do you think you would make very little money, just a few dollars, at the end of the 30-day period? Let us write a program to...
Write a C program that requests a US dollar amount from the user that will represent...
Write a C program that requests a US dollar amount from the user that will represent a restaurant bill. The program will then calculate 3 tip amounts for this bill: 10%, 15%, and 20%. Use defined constants for the tip percentages. You may use your percentages (for example) as either 10 or 0.10. If you use 10, you will need to divide this by 100 in your calculations. A sample run of this program might look like this (user input...
Design a program that calculates the amount of money a person would earn over a period...
Design a program that calculates the amount of money a person would earn over a period of time if his or her salary is one penny the first day, two pennies the second day, and continues to double each day. The program should ask the user for the number of days. Display a table showing what salary was for each day, and then show the total pay at the end of the period. The output should be displayed in a...
This program is in C++: Write a program to allow the user to: 1. Create two...
This program is in C++: Write a program to allow the user to: 1. Create two classes. Employee and Departments. The Department class will have: DepartmentID, Departmentname, DepartmentHeadName. The Employee class will have employeeID, emploeename, employeesalary, employeeage, employeeDepartmentID. Both of the above classes should have appropriate constructors, accessor methods. 2. Create two arrays . One for Employee with the size 5 and another one for Department with the size 3. Your program should display a menu for the user to...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
The Problem Write a C or C++ program which performs specific operations on bits. The user...
The Problem Write a C or C++ program which performs specific operations on bits. The user will specify a value The user can then set, test, or toggle individual bits in the initial value. Input Your program will prompt the user for: An inital value in hexadecimal. This value may be up to 32 bits (eight hexadecimal digits) long. If the user-supplied value is less than eight characters in length, assume the additional digits are zero and are on the...
Python programming:   (10pts) Write a function that calculates the tip for a meal.The user can choose...
Python programming:   (10pts) Write a function that calculates the tip for a meal.The user can choose the percentage of tip they wish to give. Show that it works by calculating an 18% tip for a meal that costs 45.89. (15pts) Write a program that computes and display the charges for a patients hospital stay. The program should ask if the person is an in-patient or an out-patient. If the patient is an in-patient, ask the user to enter the number...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT