Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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)
question from:https://stackoverflow.com/questions/65650483/need-help-adding-text-after-an-output-in-python

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
212 views
Welcome To Ask or Share your Answers For Others

1 Answer

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)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...