Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to convert a NoneType into a String?

Is there a way to convert a NoneType that the user inputs into a string, in python?
This is my code:

topping = print(input("What topping would you like on your pizza?"))
requested_toppings = []
requested_toppings.append(topping)
print("Adding" + topping + "...")
print("\n Finished Making Your Pizza!")

The error is, Type Error: can only concatenate str (not "NoneType") to str
I have tried using str(topping) between the requested toppings list and the append. What am I doing wrong? Thanks!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You do not need print() around the input function. The input function already prints the message as a prompt. The reason you are getting None is because the print function does not return anything, whereas the input function does.

Here is the corrected code:

topping = input("What topping would you like on your pizza?")
requested_toppings = []
requested_toppings.append(topping)
print("Adding" + topping + "...")
print("\n Finished Making Your Pizza!")
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading