Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Computers measure time in a number of seconds since a particular date ( 1 January 1 9 7 0 ) , which is often called
Computers measure time in a number of seconds since a particular date January which is often called the "epoch". Below, two lines of code are given that report this number to you. We will talk more about importing modules later on
import time
secondssinceepoch time.time
printThe current number of seconds since the epoch is secondssinceepoch
The current number of seconds since the epoch is
Try running this code a few times. Notice the result is different every time you run it since time is always passing!
Write two lines of code in the cell below.
The first line should use this variable secondssinceepoch and convert it into the number of whole days since the epoch. Your line of code should also save the resulting value to a variable with a descriptive name.
The second line should print the value of your new variable. Make sure your result is a whole number! If it's not, think about using a different arithmetic operation.
Hint: How many seconds are in a day?
totaldays secondssinceepoch
printtotaldays
b Seconds today
Write two lines of code in the cell below.
The first line should use the value secondssinceepoch to determine how many seconds have passed in the current day and save it to a variable. Hint: Use the modulus operator.
The second line should print the value of your new variable.
c Current time
Write code in the cell below that uses the values found in the previous parts to compute the current time of the day hours minutes, and seconds then prints it
Suggestions:
To find the current hour, you will want to use the variable for the number of seconds today that you found in part b
To find how many minutes have passed in the current hour, it may help first to compute how many seconds have passed in the current hour.
To find how many seconds have passed in the current minute, it will again help to start with the number of seconds in the current hour.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started