Help with python

I cannot get my terminal to print out the sentence. I am on mac. my terminal says that my file name is a invalid syntax and I have followed the instructions

It looks like you are treating the interactive Shell like a Command Line, which it is not. If you have a module called then you can import it, and run the functions it contains.

>>> import mycode

How make a module that I can import?

Open the editor and create your module…

from math import pi

def circumference(r):
    return pi * 2 * r

def area(r):
    return pi * r ** 2

Now Save it as From the Shell prompt,

>>> import circle
>>> circumference(5)
>>> area(5)

I saved the file in a folder of my choosing, then Run it (F5). Now in the shell the current working directory will be the one you saved the file in. That’s why I could import it directly.

I think I need to start from the beginning on how I make a module

I sort of cheated in that demo. There is a lot to learn in the meantime. Set the module concept to the side for the next few weeks while you get through the learning tracks.

We can open files using the File menu. When you locate and open the file, you can run it in the Shell. This will set the current working directory to the folder you opened the file from.

For the record, all Python files are modules, as are all functions and classes so don’t read too much into this. For now, just get used to working with the editor, saving your work and Running it in the shell. Later you will learn to work with modules included in your Python installation but that should come later, when you are more adept at coding, in general.

thanks. I am going to skip that project for now and come back when I have a better understanding of how python works.

1 Like