Question: Program: Momentum Calculator Author: Ken Lambert This program calculates the momentum of an object based on its mass and velocity. Momentum is

"""
Program: Momentum Calculator
Author: Ken Lambert
This program calculates the momentum of an object based on its mass and velocity. Momentum is defined as the product of an object's mass and its velocity.
The user will be prompted to input:
1. The mass of the object in kilograms.
2. The velocity of the object in meters per second.
Pseudocode:
1. Prompt the user to input the mass of the object in kilograms.
2. Prompt the user to input the velocity of the object in meters per second.
3. Calculate the momentum using the formula: momentum = mass * velocity.
4. Display the calculated momentum to the user with an appropriate label.
"""
def get_positive_float(prompt):
"""Function to get a positive float from the user."""
while True:
try:
value = float(input(prompt))
if value <0:
print("Please enter a non-negative number.")
else:
return value
except ValueError:
print("Invalid input. Please enter a valid number.")
def calculate_momentum():
"""Function to calculate and display the momentum of an object."""
# Input from user
mass = get_positive_float("Enter the mass of the object (in kilograms): ")
velocity = get_positive_float("Enter the velocity of the object (in meters per second): ")
# Calculate momentum
momentum = mass * velocity
# Output the results
print(f"The momentum of the object is: {momentum:.2f} kgm/s")
# Run the function to calculate momentum
if __name__=="__main__":
calculate_momentum()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!