9. Write three functions that are the “inverses" of to_secs: (a) hours_in returns the whole integer number of hours represented by a total num- ber of seconds. (b) minutes_in returns the whole integer number of left over minutes in a total number of seconds, once the hours have been taken out. (c) seconds_in returns the left over seconds represented by a total number of sec- onds. You may assume that the total number of seconds passed to these functions is an integer. Here are some test cases: test (hours_in(9010) == 2) == 30) test (minutes_in(9010) test (seconds_in (9010) 10)

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

From: How to Think Like a Computer Scientist: Learning with Python 3 -Chapter 6, Exercise 9

Write three functions that are the “inverses” of to_secs:

(a) hours_in returns the whole integer number of hours represented by a total number of seconds.

(b) minutes_in returns the whole integer number of left over minutes in a total number of seconds, once the hours have been taken out.

(c) seconds_in returns the left over seconds represented by a total number of seconds.

 

My original  to_secs function:

def to_secs(h, m, s):

total = 0

total = total + h * 60 * 60

total = total + m * 60

total = total + s

return total

thinkcspy3.pdf
Page 111 of 421
90%
thinkcspy3.pdf
7. Write a function to_secs that converts hours, minutes and seconds to a total number
of seconds. Here are some tests that should pass:
te Aece dr i e The l p veof de
te ie Aa i o ngp pEintwn
d o S ac a n i irp
A Glory
79
6.9.
Exercises
81
HieThLa C La Pyn
Demeren lee ad Ce
Cg i ty g
dl lal
tel d nr h m
In s Abu ed l t
t A ode cyou e
A o ed i fo
ppa Hig y y e
ng ing
miyi i gii r e
How to Think Like a Computer Scientist: Learning with Python 3
Documentation, Release 3rd Edition
6.9 Exercises
A as d deatde
i ue u p
iLAde e c
rv tp de d of o yoe Py
A d tere D
The tu YT T
W W c ur cns po
p d MEepp d
Timi s merlwr h
C.fodoult
test (to_secs (2, 30,
10)
9010)
%3D%3D
80
test (to_secs (2, 0, 0)
7200)
==
test (to_secs (0, 2, 0)
120)
==
test (to_secs (0, 0, 42)
42)
H T L C ie Ln Py
Donmentton. e etan
1 aga
d A kate e N tion
test (to_secs (0, -10, 10)
-590)
==
TIE I
1 e me r w ,
-1
TIL u
8. Extend to_secs so that it can cope with real values as inputs. It should always return
an integer number of seconds (truncated towards zero):
ll
4 W os or oy a W . I
andeita e
test (to_secs (2.5, 0, 10.71)
9010)
==
TIt or t
test (to_secs (2.433,0,0)
8758)
T ulaty ta y E r
=3%3=
N he wi e ofg e fc dcede e
g rvi pn T
Hh agninu h r àm nne ndri e
y nne
i m
wLI e to N er
da as tp
9. Write three functions that are the "inverses" of to_secs:
(a) hours_in returns the whole integer number of hours represented by a total num-
81
ber of seconds.
(b) minutes_in returns the whole integer number of left over minutes in a total
number of seconds, once the hours have been taken out.
Hie ThL C L yn
Demerten. lee nd Ceon
im he l,
imh ils
TIt KJ
A ed he a md nin s n ws
.4
Wda fa ta oltCE
osci wwdeo berf tby
(c) seconds_in returns the left over seconds represented by a total number of sec-
w p er leh a
onds.
be omd.c bou a o
H LI T H
Te f t pdiefc mie
Wew e
TI is
i ser
dre de I
You may assume that the total number of seconds passed to these functions is an integer.
n ynd
T sin. ing
bow h ap er in e
Here are some test cases:
S o N ca y Hat
IN M do f
k ingr hng
Comp Si od fho t t dk el a
test (hours_in(9010)
2)
Ww ia
==
test (minutes_in(9010)
30)
Chu ra ncons
===
test (seconds_in (9010)
10)
==
82
Transcribed Image Text:thinkcspy3.pdf Page 111 of 421 90% thinkcspy3.pdf 7. Write a function to_secs that converts hours, minutes and seconds to a total number of seconds. Here are some tests that should pass: te Aece dr i e The l p veof de te ie Aa i o ngp pEintwn d o S ac a n i irp A Glory 79 6.9. Exercises 81 HieThLa C La Pyn Demeren lee ad Ce Cg i ty g dl lal tel d nr h m In s Abu ed l t t A ode cyou e A o ed i fo ppa Hig y y e ng ing miyi i gii r e How to Think Like a Computer Scientist: Learning with Python 3 Documentation, Release 3rd Edition 6.9 Exercises A as d deatde i ue u p iLAde e c rv tp de d of o yoe Py A d tere D The tu YT T W W c ur cns po p d MEepp d Timi s merlwr h C.fodoult test (to_secs (2, 30, 10) 9010) %3D%3D 80 test (to_secs (2, 0, 0) 7200) == test (to_secs (0, 2, 0) 120) == test (to_secs (0, 0, 42) 42) H T L C ie Ln Py Donmentton. e etan 1 aga d A kate e N tion test (to_secs (0, -10, 10) -590) == TIE I 1 e me r w , -1 TIL u 8. Extend to_secs so that it can cope with real values as inputs. It should always return an integer number of seconds (truncated towards zero): ll 4 W os or oy a W . I andeita e test (to_secs (2.5, 0, 10.71) 9010) == TIt or t test (to_secs (2.433,0,0) 8758) T ulaty ta y E r =3%3= N he wi e ofg e fc dcede e g rvi pn T Hh agninu h r àm nne ndri e y nne i m wLI e to N er da as tp 9. Write three functions that are the "inverses" of to_secs: (a) hours_in returns the whole integer number of hours represented by a total num- 81 ber of seconds. (b) minutes_in returns the whole integer number of left over minutes in a total number of seconds, once the hours have been taken out. Hie ThL C L yn Demerten. lee nd Ceon im he l, imh ils TIt KJ A ed he a md nin s n ws .4 Wda fa ta oltCE osci wwdeo berf tby (c) seconds_in returns the left over seconds represented by a total number of sec- w p er leh a onds. be omd.c bou a o H LI T H Te f t pdiefc mie Wew e TI is i ser dre de I You may assume that the total number of seconds passed to these functions is an integer. n ynd T sin. ing bow h ap er in e Here are some test cases: S o N ca y Hat IN M do f k ingr hng Comp Si od fho t t dk el a test (hours_in(9010) 2) Ww ia == test (minutes_in(9010) 30) Chu ra ncons === test (seconds_in (9010) 10) == 82
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 5 steps with 1 images

Blurred answer
Knowledge Booster
Function Arguments
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education