answer.
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]
2 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:
Alex2 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
You resurrected an old worksheet. It appears to contain most of the information that you need, but not all of it. Which step sho
vagabundo [1.1K]

Answer:

The answer is "check the worksheet is not read only"

Explanation:

The read only mode is used for read the file data, and it doesn't allows the user to update the file, and for updating the worksheet we should check iut does not open in the read-only mode.

If it is open, then we close it and for close we goto the office button and click on the tools option after that goto general setting, in this there is a check box for turn off the read-only mode.

 

8 0
2 years ago
Write a algorithm to attend birthday party​
kolezko [41]

Answer:

2     No

5 14    Yes

Explanation:

8 0
2 years ago
Read 2 more answers
George is working with an image in Photoshop. He added a lot of effects to the image. He saved the first draft of the file. The
Alja [10]

Answer:

JPEG, PDF

Explanation:

3 0
2 years ago
Read 2 more answers
Write an expression that will cause the following code to print "I am a teenager" if the value of userAge is less than 20. Zyboo
VikaD [51]

Answer:

Replace

if userAge > 20

with

userAge > 19

Explanation:

if userAge > 20  checks if age is 21, 22, 23, 24........

The else condition which prints "I am a teenager" checks if age is 20, 19, 18....

Notice that 20 is inclusive of the else condition; this shouldn't be because for userAge to be less than 20, 20 isn't inclusive

To solve this,

Replace if userAge > 20 with userAge > 19

So that, the else

The else condition which prints "I am a teenager" checks if age is 19, 18, 17, 16....

6 0
2 years ago
You are a technical consultant for many businesses in your community. One of your clients, a small law firm, has a single Active
stellarik [79]

COMPLETE QUESTION:

You are a technical consultant for many businesses in your community. One of your clients, a small law firm, has a single Active Directory domain. They have two servers running Windows Server 2012 R2. Both servers are configured as domain controllers while also serving as file and printer servers.This client is calling you on a regular basis because users are deleting or damaging their files. You must visit the client's site and restore the files from backup. Your client has asked you to create an alternate solution. What should you do?

Answer:

Use the Windows VSS to create shadow copies on important data

Explanation:

Volume Snapshot Service (VSS) is a service available to Windows Operating Systems which allows safe backup of open files as well as locked ones. It does this by taking a snapshot the state of the drive, this snapshot information will be provided to the backup application whenever needed. It is important to mention that this service is only available on files which are in the NTFS format

8 0
2 years ago
Other questions:
  • Which statement regarding dialogues in multiplayer games is true? Dialogues are based only on players’ actions.
    7·2 answers
  • The piston engine uses the ________ to convert the reciprocating motion of the piston into rotary motion.
    13·1 answer
  • In what year were graphical user interfaces (GUIs) pioneered? 1969 1974 1991 2001
    12·2 answers
  • Import java.util.scanner; public class sumofmax { public double findmax(double num1, double num2) { double maxval; // note: if-e
    10·1 answer
  • Write a copy constructor for carcounter that assigns origcarcounter.carcount to the constructed object's carcount. sample output
    15·2 answers
  • Write a program in c or c++ to perform different arithmeticoperation using switch statement .the program will take two inputinte
    10·1 answer
  • python Write a function that computes a future investment value at a given interest rate for a specified number of years. The fu
    11·1 answer
  • Write the notInVocab method. Assume that there are no duplicates in wordArray. You must call findWord and countNotInVocab approp
    10·1 answer
  • What are some reasons DNS is necessary? Check all that apply. A. It maps local addresses to simple names without editing hosts f
    7·1 answer
  • Write a split check function that returns the amount that each diner must pay to cover the cost of the meal The function has 4 p
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!