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
Anyone play Ro-blox ? without the -
Olin [163]
I do! I know it says high school but I lied :)
6 0
3 years ago
Read 2 more answers
What is the best stratiget to avoid paying intrest in your credit cared
pochemuha
Paying it in full month over month.
4 0
3 years ago
A(n) ________ is a text or image that allows the user to access that file or web page with a single click.
son4ous [18]
It would be called a link. Connection might work as well. 
5 0
3 years ago
Read 2 more answers
Question 4 of 20
Verdich [7]

Answer:

B

Explanation:

8 0
3 years ago
. What is automated testing?
shepuryov [24]

Answer: Automated testing is testing of the software by the means of automation by using special tools .These software tools are responsible for the testing of the execution process , functioning and comparing the achieved result with actual result.

It is helps in achieving the accuracy as compared with manual testing and also also function without any human interruption.It produces the test scripts that can be re-used.

8 0
4 years ago
Other questions:
  • Decisions 1 and 3 are both ____________ decisions because ____________________.
    9·1 answer
  • If we have an economy that operates with a minimum of government interference, why are there so many laws on the books about emp
    7·2 answers
  • Who is known as the father of computer? ​
    6·2 answers
  • How to add a second screen to your computer?
    7·1 answer
  • Suppose arraylist list1 is [1, 2, 5] and arraylist list2 is [2, 3, 6]. after list1.addall(list2), list1 is __________.
    8·1 answer
  • 5. What is the purpose of OneDrive? A. OneDrive organizes files on an external hard drive. B. OneDrive allows the user to work o
    7·1 answer
  • You dad has given you his old digital scanner for your new computer. you plug it into the usb drive on your windows 8 computer b
    8·1 answer
  • NO LINKS<br> Do you need to pay monthly to stream on Twitch?
    5·1 answer
  • If your tired but still need to proofread your document,what should you do?
    15·2 answers
  • "Automated Deployment" is one of the prerequisite for DevOps implementation.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!