Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a function named generate _ temperatures that works with the code below. The function should generate and print random temperatures between the coldest temperature

Write a function named generate_temperatures that works with the
code below. The function should generate and print random temperatures between the coldest
temperature and the hottest temperature until a temperature is generated that is close enough to
the desired temperature. Your program can make the following assumptions: (1) the values of
all four parameters are floating point numbers, (2) the coldest_temperature is less than the
hottest_temperature, (3) the desired_temperature is somewhere between the coldest_temperature
and the hottest_temperature and (4) how_close is 1.0 or greater.
def main():
c oldest_temperature =-70.0
# The coldest temperature (could be any value)
hottest_temperature =117.5 # The hottest temperature (could be any value)
desired_temperature =72.7 # A subjective ideal temperature (could be any value)
how_close =9.9
# Closeness to desired temperature (could be any value)
generate_temperatures(coldest_temperature, hottest_temperature, \
desired_temperature, how_close)
main()
What follows is a sample run that generates four random temperatures before stopping. The run
stops because the 78.11 temperature is within 9.9 degrees of the desired temperature.
-11.68
-10.16
54.53
78.11

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions