1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] Why does my Python code only run when I save it in a file with nano and not directly...

Discussão em 'Python' iniciado por Stack, Setembro 16, 2025.

  1. Stack

    Stack Membro Participativo

    Body: I’m learning Python on WSL. When I paste my code directly into the terminal, nothing prints. But if I open nano, paste the code, save it as functions.py, and then run python functions.py, it works and prints as expected.

    Example code:

    def multiply(a, b):
    return a * b

    print(multiply(2, 4))


    Why does the code not execute when I paste it directly in the terminal, but works when I save it as a file and run it?

    I expected the code to print output directly when pasted into the terminal, just like it does when I save and run it as a script.

    Continue reading...

Compartilhe esta Página