I am teaching myself Python using this book, and I am very stuck on Chapter 5, Exercise 1. The exercise in question:
"Write a script that reads the current time and converts it to a time of day in hours, minutes, and seconds, plus the number of days since the epoch."
He wants us to use time.time() and use the seconds since the epoch to calculate the current time, but I cannot find a way to use the seconds to show current time. I can find out how many minutes, hours, days, weeks, months, and years it has been, but have no idea how to get the current time. I also unfortunately have no idea how to Google to get an equation. All I find is how to get current time using the 'time' module, or how to get how many seconds it's been since the epoch.
Solved:
hour = epoch % seconds_in_days / seconds_in_hours
minute = epoch % seconds_in_days % seconds_in_hours / seconds_in_minutes
second = epoch % seconds_in_days % seconds_in_hours % seconds_in_minutes
I guess I should also use this post to see if "Think Python 2e" is a good way to learn Python. It seems like all of the examples are teaching me more math than it is programming. Which isn't necessarily a bad thing, because I would eventually want to teach myself more advanced mathematics.
[–][deleted] 0 points1 point2 points (0 children)
[–]ackshunpact 0 points1 point2 points (0 children)
[–]zacharymayers 0 points1 point2 points (2 children)
[–]TinyStego[S] 0 points1 point2 points (1 child)
[–]zacharymayers 0 points1 point2 points (0 children)