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
Topic Video
Question

1.1

 

def rest_time (miles_driven, brake_count):
Backstory: In the city of Slotham, Slothman is the silent guardian and savior of the people. He has
his own Slothmobile, which is no less impressive than the Batmobile. However, Slothmobile gets
tired after running for some time and recovers when it is turned off! It other words, it needs to
rest before it turns on again. The number of hours it needs to rest depends on how many miles it
was driven and how many times the brakes were applied after the last time it was switched on.
Description: You can figure out the number of hours the Slothmobile needs to rest by counting
the number of times you get an even number (excluding 0) when you integer divide the number of
miles driven by the number of times the brakes are applied.
For example, if miles driven is 13 and brakes applied is 2, 13 divided by 2 is 6.5, which rounds
down to 6, which is even. Next, we will consider 6 to see if we get any more even integers. 6
integer divided by 2 is 3, since 3 is odd, we stop here. So, the rest time for Slothmobile is 1 hour
because we only calculated 1 even number in these integer divisions.
Parameters: miles_driven (int, indicating the number of miles driven)
brake_count (int, indicating the number of times brakes applied)
Assumptions: Both parameters are positive integers (> 0)
Return value: An integer, which represents Slothmobile rest time in hours
Examples:
rest_time(13, 2) → 1
rest_time(9, 3) → 0
rest_time(24, 3) → 2
# 13 → 6→ 3; 6 is even → 1 hour
#93; no even number → 0 hour
# 2482 → 0; 8, 2 are even (we exclude 0) → 2 hours
Transcribed Image Text:def rest_time (miles_driven, brake_count): Backstory: In the city of Slotham, Slothman is the silent guardian and savior of the people. He has his own Slothmobile, which is no less impressive than the Batmobile. However, Slothmobile gets tired after running for some time and recovers when it is turned off! It other words, it needs to rest before it turns on again. The number of hours it needs to rest depends on how many miles it was driven and how many times the brakes were applied after the last time it was switched on. Description: You can figure out the number of hours the Slothmobile needs to rest by counting the number of times you get an even number (excluding 0) when you integer divide the number of miles driven by the number of times the brakes are applied. For example, if miles driven is 13 and brakes applied is 2, 13 divided by 2 is 6.5, which rounds down to 6, which is even. Next, we will consider 6 to see if we get any more even integers. 6 integer divided by 2 is 3, since 3 is odd, we stop here. So, the rest time for Slothmobile is 1 hour because we only calculated 1 even number in these integer divisions. Parameters: miles_driven (int, indicating the number of miles driven) brake_count (int, indicating the number of times brakes applied) Assumptions: Both parameters are positive integers (> 0) Return value: An integer, which represents Slothmobile rest time in hours Examples: rest_time(13, 2) → 1 rest_time(9, 3) → 0 rest_time(24, 3) → 2 # 13 → 6→ 3; 6 is even → 1 hour #93; no even number → 0 hour # 2482 → 0; 8, 2 are even (we exclude 0) → 2 hours
2
3
4
5
6
7
8
9
10
11
(known limitations)
def rest_time (miles_driven, brake_count):
count = 0
count = round(miles_driven/brake_count)
counter = 0
while (count % 2)
count = (count/2)
if counter >= 0:
if count <= 1:
H = "hour"
else:
==
counter = counter + 1
:
H = "hours"
12
13
14
15
16
► 17 print (rest_time (24,3)) #fix me
return str (counter) +" + H
"1
3 hour
Fra
Global fra
rest_time
Transcribed Image Text:2 3 4 5 6 7 8 9 10 11 (known limitations) def rest_time (miles_driven, brake_count): count = 0 count = round(miles_driven/brake_count) counter = 0 while (count % 2) count = (count/2) if counter >= 0: if count <= 1: H = "hour" else: == counter = counter + 1 : H = "hours" 12 13 14 15 16 ► 17 print (rest_time (24,3)) #fix me return str (counter) +" + H "1 3 hour Fra Global fra rest_time
Expert Solution
steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Instruction Format
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