1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
GalinKa [24]
4 years ago
12

Using the format method, fill in the gaps in the convert_distance function so that it returns the phrase "X miles equals Y km",

with Y having only 1 decimal place. For example, convert_distance(12) should return "12 miles equals 19.2 km".
1 an AWN def convert_distance (miles): km = miles * 1.6 result = "{} miles equals {_} km". _ return result 7 8 print(convert_distance(12)) # should be: 12 miles equals 19.2 km print(convert_distance(5.5)) # should be: 5.5 miles equals 8.8 km print(convert distance(11)) # Should be: 11 miles equals 17.6 km

Computers and Technology
1 answer:
Alex4 years ago
6 0

Answer:

Add this statement to the code using format method:

result = "{} miles equals {:.1f} km".format(miles,km)

Explanation:

Here is the complete program:

def convert_distance (miles):

   km = miles * 1.6

   result = "{} miles equals {:.1f} km".format(miles,km)

   return result    

print(convert_distance(12))# should be: 12 miles equals 19.2 km

print(convert_distance(5.5)) # should be: 5.5 miles equals 8.8 km

print(convert_distance(11)) # Should be: 11 miles equals 17.6 km

The format() method is used to format the values of the specified parameters and insert the formatted values into the curly brackets which are called placeholders. The parameters of format() method here are miles and km . The first placeholder is for formatted value of miles variable and second placeholder is for formatted value of km variable. Note that placeholder for km has {:.1f} which means the value of km is rounded to 1 decimal place. For example if the value is 19.23245 then it is displayed up to 1 decimal place as: 19.2

The above program has a method convert_distance that takes miles as parameter and converts the value of miles to km by formula:

km = miles * 1.6

It then displays the output in the specified format using format() method. Now lets take an example:

print(convert_distance(5.5))

The above statement calls the method by passing the value 5.5 So,

miles = 5.5

Now the function converts this value to km as:

km = miles * 1.6

km = 5.5 * 1.6

km = 8.8

Statement: result = "{} miles equals {:.1f} km".format(miles,km) becomes:

{} first place holder holds the value of miles i.e. 5.5

{} second place holder holds the value of km up to 1 decimal place i.e. 8.8

Hence it becomes:

5.5 miles equals 8.8 km

So return result  returns the result of this conversion.

Hence the output is:

5.5 miles equals 8.8 km

The program and its output is attached.

You might be interested in
. A search engine is a way to
Sindrei [870]
<span>Option A, the search engine is the way to get information on the internet through a web browser, installed on an operating system of a computer. It is software that gathers all the information and stores it to accelerate the search for the users by entering the data of the desired information.</span>
8 0
4 years ago
Read 2 more answers
What does the octal number 362 represent in the decimal system?
kykrilka [37]
The answer is E. 242
8 0
3 years ago
Given six memory partitions of 300 KB, 600 KB, 350 KB, 200 KB, 750 KB, and 125 KB (in order), how would the first-fit, best-fit,
Inga [223]

Answer:

In terms of efficient use of memory: Best-fit is the best (it still have a free memory space of 777KB and all process is completely assigned) followed by First-fit (which have free space of 777KB but available in smaller partition) and then worst-fit (which have free space of 1152KB but a process cannot be assigned). See the detail in the explanation section.

Explanation:

We have six free memory partition: 300KB (F1), 600KB (F2), 350KB (F3), 200KB (F4), 750KB (F5) and 125KB (F6) (in order).

Using First-fit

First-fit means you assign the first available memory that can fit a process to it.

  • 115KB will fit into the first partition. So, F1 will have a remaining free space of 185KB (300 - 115).
  • 500KB will fit into the second partition. So, F2 will have a remaining free space of  100KB (600 - 500)
  • 358KB will fit into the fifth partition. So, F5 will have a remaining free space of 392KB (750 - 358)
  • 200KB will fit into the third partition. So, F3 will have a remaining free space of 150KB (350 -200)
  • 375KB will fit into the remaining partition of F5. So, F5 will a remaining free space of 17KB (392 - 375)

Using Best-fit

Best-fit means you assign the best memory available that can fit a process to the process.

  • 115KB will best fit into the last partition (F6). So, F6 will now have a free remaining space of 10KB (125 - 115)
  • 500KB will best fit into second partition. So, F2 will now have a free remaining space of 100KB (600 - 500)
  • 358KB will best fit into the fifth partition. So, F5 will now have a free remaining space of 392KB (750 - 358)
  • 200KB will best fit into the fourth partition and it will occupy the entire space with no remaining space (200 - 200 = 0)
  • 375KB will best fit into the remaining space of the fifth partition. So, F5 will now have a free space of 17KB (392 - 375)

Using Worst-fit

Worst-fit means that you assign the largest available memory space to a process.

  • 115KB will be fitted into the fifth partition. So, F5 will now have a free remaining space of 635KB (750 - 115)
  • 500KB will be fitted also into the remaining space of the fifth partition. So, F5 will now have a free remaining space of 135KB (635 - 500)
  • 358KB will be fitted into the second partition. So, F2 will now have a free remaining space of 242KB (600 - 358)
  • 200KB will be fitted into the third partition. So, F3 will now have a free remaining space of 150KB (350 - 200)
  • 375KB will not be assigned to any available memory space because none of the available space can contain the 375KB process.
8 0
3 years ago
In 25 words or fewer, identify what calendar feature the recurring task function copies.
alexdok [17]
Shhsnanwnwnsjssnsnnwnsn
7 0
4 years ago
The general who directed the project responsible for the "Fat Man” graduated from what alma mater in 1918?
krek1111 [17]
Stafford Leak Warren (July 19, 1896 - July 26, 1981) was an American physician and ... He was responsible<span> for the health and safety of the thousands of personnel ... The medical school had opened in 1925 and did not </span>graduate<span> its first class ... Brigadier</span>General<span> Leslie R. Groves, the director of the Manhattan </span>Project<span> </span>
7 0
4 years ago
Read 2 more answers
Other questions:
  • 30 POINTS!!
    15·2 answers
  • A user is connecting to an e-commerce server to buy some widgets for a company. the user connects to the site and notices there
    10·1 answer
  • What effect does the interconnectedness of modern media have on society?
    14·2 answers
  • What is GND and what color wire do we connect to GND? (this is like for circuits and stuff btw)
    7·1 answer
  • Write a recursive method that tests whether a string is a palindrome. It should return a boolean T or F depending on whether or
    6·1 answer
  • A user from the sales department calls to report that he is experiencing problems connecting to the sales file server. All users
    15·1 answer
  • Disadvantages of computer. ​
    9·1 answer
  • What is a client server network and its features?​
    11·1 answer
  • What are the steps to view two different versions of the same document at once? 1. Go to the File tab on the ribbon. 2. Select T
    6·1 answer
  • Please define processor​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!