This is what ChatGPT replied after i asked if my code was correct, but this the result I'm getting in Jupyter notebooks
Can someone explain what what am I doing wrong and how to correct it?
This is what ChatGPT replied after i asked if my code was correct, but this the result I'm getting in Jupyter notebooks
Can someone explain what what am I doing wrong and how to correct it?
Where i went wrong
You should not ask AI if your code is correct, neither you should ask AI to run your code, and debug it based on that ...
What to do now
Look into documentation, for example https://www.w3schools.com/python/ref_string_format.asp you will see how the format function on strings work ...
Therefore printing "hello world" is correct. You can just run the python script yourself or use an online sandbox i.e https://pythonsandbox.com/code/pythonsandbox_u63345_FUpPnsgumRsxsdzUSVg59LzU_v0.py to verify this
The output you see in Jupyter Notebook is the correct one. ChatGPT should never be used as a tool to generate the output for the code. ChatGPT is a generative model that generates the output based on the data it is trained on. It never runs your code in real environment to give the output. So, you should never use and believe on the output that ChatGPT or any other generative models produces.
Always verify and test the code given by ChatGPT in real programming environment.
How string's format
function works is, it inserts the specified values in the string placeholder. Placeholders are defined by curly braces ({}
).
For eg.
text_1 = "Hello {0}".format("Everyone")
For above example, it will generate the output as Hello Everyone
.
But if you never specify a string placeholder then nothing in the string will be replaced by the provided value.
In your case, there is no string placeholder, so the output will be same as your inputed string.