Reputation: 17
I want someone to input their weight in lbs which is then converted to kg. However the output is just the converted number. I can't figure out how to label the output with "kg". ex: 72 kg
weight_lbs = input('Weight (lbs): ')
weight_kg = int(weight_lbs) * 0.45
kg = 'kg'
print(weight_kg + kg)
Upvotes: 0
Views: 93
Reputation: 6090
Another version of the twice upvoted answer:
weight_lbs = input('Weight (lbs): ')
weight_kg = str(int(weight_lbs) * 0.45)
kg = 'kg'
print(weight_kg + kg)
Upvotes: 0
Reputation: 13
You can also just use %s and get rid of 'kg' = kg
print("%s %s" % (weight_kg,"kg"))
Upvotes: 0
Reputation: 1139
you need to do str(weight_kg)
to make it a string type (instead of a number)
weight_lbs = input('Weight (lbs): ')
weight_kg = int(weight_lbs) * 0.45
kg = 'kg'
print(str(weight_kg) + kg)
Upvotes: 2