0

ChatGPT answer

This is what ChatGPT replied after i asked if my code was correct, but this the result I'm getting in Jupyter notebooks

Jupyter Output

Can someone explain what what am I doing wrong and how to correct it?

Tzane
  • 2,752
  • 1
  • 10
  • 21
  • 1
    As others have said in their answers, ChapGPT, contrary to the hype is a chatbot and will invent responses based on your input. Whether those responses are technically correct or not is entirely random. These chatbots are designed to respond in ways that *seem* plausible, not in ways that are *correct*, and should only really be used to generate copy that has no real-world actual value or meaning. They're toys, or at best, can be used to write "filler" text on which nobody might accidentally rely on to tell the truth. To imagine otherwise is problematic at best, and very dangerous at worst. – Thomas Kimber Aug 14 '23 at 10:05

2 Answers2

1

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

john Smith
  • 17,409
  • 11
  • 76
  • 117
1

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.

Ankush Chavan
  • 1,043
  • 1
  • 6
  • 20