A ball is dropped from a given initial height and rebounds every time it hits the ground. Each time it rebounds, it reaches a new height that is a fraction of the previous height. Define a function travel_distance that returns the total distance traveled by the ball after it rebounds a number of times until it reaches a new height. Parameters: height: a non-negative floating-point number specifying the initial height the ball is dropped from. co: the fraction in \((0,1)\) of the new height with respect to the previous height. times: the number of times the ball rebounds. Allow users to pass None to the parameter times to compute the total distance traveled as times goes to infinity. Hint: Be careful not to write an infinite loop. It is possible to write the function body in one line.

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

A ball is dropped from a given initial height and rebounds every time it hits the ground. Each time it rebounds, it reaches a new height that is a fraction of the previous height. Define a function travel_distance that returns the total distance traveled by the ball after it rebounds a number of times until it reaches a new height.

  • Parameters:
    • height: a non-negative floating-point number specifying the initial height the ball is dropped from.
    • co: the fraction in \((0,1)\) of the new height with respect to the previous height.
    • times: the number of times the ball rebounds.

Allow users to pass None to the parameter times to compute the total distance traveled as times goes to infinity.

Hint: Be careful not to write an infinite loop. It is possible to write the function body in one line.

Hint: Be careful not to write an infinite loop. It is possible to write the function body in
one line.
For example:
Test
import math
v = travel_distance (100, 0.5, 0)
assert math.isclose(v, 0)
print('{:.2f)'.format(travel_distance
print('{:.2f} .format(travel_distance
print('{:.2f}'.format(travel_distance
Result
(100, 0.5, 1)))
(100, 0.5, 2)))
(100, 0.5, None))) 300.00
150.00
225.00
4
Transcribed Image Text:Hint: Be careful not to write an infinite loop. It is possible to write the function body in one line. For example: Test import math v = travel_distance (100, 0.5, 0) assert math.isclose(v, 0) print('{:.2f)'.format(travel_distance print('{:.2f} .format(travel_distance print('{:.2f}'.format(travel_distance Result (100, 0.5, 1))) (100, 0.5, 2))) (100, 0.5, None))) 300.00 150.00 225.00 4
A ball is dropped from a given initial height and rebounds every time it hits the ground.
Each time it rebounds, it reaches a new height that is a fraction of the previous height.
Define a function travel_distance that returns the total distance traveled by the ball
after it rebounds a number of times until it reaches a new height.
Parameters:
0 height: a non-negative floating-point number specifying the initial height the ball
is dropped from.
oco: the fraction in \((0,1)) of the new height with respect to the previous height.
o times: the number of times the ball rebounds.
Allow users to pass None to the parameter times to compute the total distance traveled
as times goes to infinity.
Hint: Be careful not to write an infinite loop. It is possible to write the function body in
one line.
For example:
Test
import math
v = travel_distance (100, 0.5, 0)
assert math.isclose(v, 0)
Result
Transcribed Image Text:A ball is dropped from a given initial height and rebounds every time it hits the ground. Each time it rebounds, it reaches a new height that is a fraction of the previous height. Define a function travel_distance that returns the total distance traveled by the ball after it rebounds a number of times until it reaches a new height. Parameters: 0 height: a non-negative floating-point number specifying the initial height the ball is dropped from. oco: the fraction in \((0,1)) of the new height with respect to the previous height. o times: the number of times the ball rebounds. Allow users to pass None to the parameter times to compute the total distance traveled as times goes to infinity. Hint: Be careful not to write an infinite loop. It is possible to write the function body in one line. For example: Test import math v = travel_distance (100, 0.5, 0) assert math.isclose(v, 0) Result
Expert Solution
steps

Step by step

Solved in 4 steps with 3 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