Skip to main content

Python Practice - Ask weight in pound and convert it to kg

Submitted by admin on Wed, 12/08/2021 - 12:56
Python convert weight
In this python practice, we will ask user to input weight in pound and convert the weight in kg.


weight_pound = input("what is your weight in pound? ")
weight_kg = int(weight_pound) * 0.45
print("Your weight in KG is " + str(weight_kg))

Code Explanation

On line 1:
we ask user to input weight in pound.


weight_pound = input("what is your weight in pound? ")

On line 2:
Input function always return string type value. So, we have converted weight_pound to integer type and multiplied it by 0.45. The result is saved as weight_kg


weight_kg = int(weight_pound) * 0.45

On line 3:
We print the value of weight_kg


print("Your weight in KG is " + str(weight_kg))

Category

Add new comment

Restricted HTML

  • Allowed HTML tags: <a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id>
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.