104k views
5 votes
Write a program that asks a user for a weight in pounds (possibly fractional), and outputs the weight in kilograms. (For the record, 1 pound equals approximately 0.45359 kilograms.)

User Nick Soper
by
4.6k points

1 Answer

6 votes

Step-by-step explanation:

Input is taken from the user in pounds and conversion from pounds to kilograms is done in the print function using the conversion rate given in the problem. eval is used ensure numeric input from the user and it can also handle fractional values.

Python Code:

value=eval(input("Please enter the weight in pounds: "))

print("The weight in kg is: ", value*0.45359)

Output:

Please enter the weight in pounds: 85.5

The weight in kg is: 38.781945

Please enter the weight in pounds: 150.56

The weight in kg is: 68.2925104

Write a program that asks a user for a weight in pounds (possibly fractional), and-example-1
User Don Dickinson
by
4.0k points