What is the error here?

When you create a file write command - sudo nano demo.py

The . py extension show that your file contain python document

And .txt is for text document

Please save your file as “demo.py” instead of “demo.txt” and also remove “sum” from the file name.
When you use .txt extension ubuntu cannot identify the file as a python file therefore showing an error .
After saving the file, run the following line of command: sudo python3 demo.py
Hope it solves your doubt.