My first program
Using the interactive IPython shell alone is exciting only for a while. To write more complex programs, you need to store your instructions in programs, so that you can execute them later.
In this section we will write our first Python program. It is going to simply write a few names of babies to the screen.
Exercise 1
Open a text editor (e.g. Spyder) and create a new file. Write into it:
print("Hannah")
print(23073)
Save the file with the name output.py
ab.
Exercise 2
Now let's execute our program.
- In Anaconda Spyder you can use the "Play" button or press
F5
. In Unix open a terminal, change to the directory with the Python file and type:
python3 output.py
Exercise 3
Explain the following program:
name = "Emily"
jahr = 2000
print(name, jahr)
Exercise 4
Write the following program:
name = "Emily"
name
What happens when you execute the code?