Michael Kreiler
Michael Kreiler

Reputation: 17

Need help adding text after an output in python

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

Answers (3)

Synthaze
Synthaze

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

frogs114
frogs114

Reputation: 13

You can also just use %s and get rid of 'kg' = kg

print("%s %s" % (weight_kg,"kg"))

Upvotes: 0

MaxYarmolinsky
MaxYarmolinsky

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

Related Questions