-2

I’m new to Python and programming altogether. As I’m going through my first few online lessons, I’m trying to add text to the users weight i.e. 70kg’s

My code that works is as follows:

weight_lbs = input(“Please enter your weight in pounds? “)

weight_kg = int(weight_lbs) * 0.45

print(weight_kg)

Nb: the above code works but does not display the text “kg’s” after the number.

I’ve tried: print(weight_kg) + “kg’s” or print(weight_kg + “kg’s”) or print(weight_kg), “kg’s”

Unfortunately I keep getting error, unsupported operand type(s) for +: ‘NoneType’ and ‘Str’

Thanks in advance

Mark

Van Wilder
  • 21
  • 2
  • 5
  • Please format the code - select it and type `ctrl-k`. .. [Formatting help](https://stackoverflow.com/editing-help)... [Formatting sandbox](https://meta.stackexchange.com/questions/3122/formatting-sandbox) – wwii Jun 08 '20 at 22:59
  • 1
    Does this answer your question? [Which is the preferred way to concatenate a string in Python?](https://stackoverflow.com/questions/12169839/which-is-the-preferred-way-to-concatenate-a-string-in-python) – wwii Jun 08 '20 at 23:00
  • Does this answer your question? [Error with print: unsupported operand type(s) for +: 'NoneType' and 'str'](https://stackoverflow.com/questions/26422819/error-with-print-unsupported-operand-types-for-nonetype-and-str) – Gino Mempin Jun 09 '20 at 00:08
  • 1
    Does this answer your question? [How can I concatenate str and int objects?](https://stackoverflow.com/q/25675943/2745495) – Gino Mempin Jun 09 '20 at 00:10
  • @wwii no, that's definitely the wrong one here. – Karl Knechtel Sep 09 '22 at 07:38

1 Answers1

-1
print(f"{weight_kg}kg's")

or simply

print(str(weight_kg)+"kg's")
  • Thank you so much. The second one definitely did the trick. Did not quite understand the syntax in the first one though but that’s okay..I’ll remember the second solution going forward – Van Wilder Jun 09 '20 at 08:00