Python_Lab_2_Functions

An object’s momentum is its mass multiplied by its velocity. The kinetic energy of a moving object is given by the formula

KE=(1/2)mv2, where m is the object’s mass and v is its velocity squared.

Write two functions one for momentum and the other for kinetic energy.

The momentum function must have two required parameters and calculates/prints the object's momentum.

The kinetic energy function must have two required parameters and calculate/print the

kinetic energy.

Write a program that accepts an object’s mass (in kilograms) and velocity (in meters

per second) as inputs and then outputs its momentum and kinetic energy by calling the functions.

Respuesta :

Answer:

Program written in Python

def KEfunction(mass,velocity):

    KE = 0.5 * mass * velocity**2

    print("Kinetic Energy: "+str(KE))

def momentum(mass,velocity):

    P= mass * velocity

    print("Momentum: "+str(P))

Mass = float(input("Mass (kg): "))

Velocity = float(input("Velocity (m/s): "))

KEfunction(Mass,Velocity)

momentum(Mass,Velocity)

Explanation:

This line defines the kinetic energy function

def KEfunction(mass,velocity):

This line calculates the kinetic energy

    KE = 0.5 * mass * velocity**2

This line prints the kinetic energy

    print("Kinetic Energy: "+str(KE))

This line defines the momentum function

def momentum(mass,velocity):

This line calculates the momentum

    P= mass * velocity

This line prints the momentum

    print("Momentum: "+str(P))

The main method begine here

This line prompts user for mass

Mass = float(input("Mass (kg): "))

This line prompts user for velocity

Velocity = float(input("Velocity (m/s): "))

This line calls the kinetic function

KEfunction(Mass,Velocity)

This line calls the momentum function

momentum(Mass,Velocity)