Coding

Q1. Write a program that asks the user to enter a distance in kilometers, and then converts that distance to miles. The conversion formula is as follows:

                          Miles  Kilometer x 0.6214

Submission for Q1:

  1. A Python code file
  2. Screenshot of the Running program

Q2. Write the following codes

Submission of Q2 (All parts a, b, and c):

  1. A summary of the program, what does program do
  2. Screenshot of the Running program

a). def message():

           print('I am Arthur,')

           print('King of the Britons.')

message()

find the cost of your paper

Sample Answer

 

 

Q1:

Python code:

Python
def kilometers_to_miles():
    kilometers = float(input("Enter a distance in kilometers: "))
    miles = kilometers * 0.6214
    print(kilometers, "kilometers is equal to", miles, "miles.")

kilometers_to_miles()

Description of execution:

  1. The program prompts the user to enter a distance in kilometers.
  2. It converts the input to a floating-point number and stores it in the kilometers variable.

Full Answer Section

 

 

 

  1. It multiplies kilometers by 0.6214 to calculate the distance in miles.
  2. It prints a statement displaying both the original distance in kilometers and the converted distance in miles.

Q2a:

Python code:

Python
def message():
    print("I am Arthur,")
    print("King of the Britons.")

message()

Summary:

This program defines a function called message() that prints two lines of text: “I am Arthur,” and “King of the Britons.” It then calls the message() function to execute those print statements.

Description of execution:

  1. The message() function is defined.
  2. When called, it prints “I am Arthur,” on a line by itself.
  3. It then prints “King of the Britons.” on another line.
  4. The program ends.

This question has been answered.

Get Answer