Python Programming - Getting Started
This page is part of Programming and CS - Getting Started
For a video explaining how to get started here, see https://www.youtube.com/watch?v=uLnhcCZS4-Y&t=424s
- Reading - start reading through at least one of the following before you start working on the programming problems.
- Learn Python - interactive tutorial where you can try out code in the browser
- Automate the Boring Stuff with Python - suitable for people with very limited programming experience, this is the text that is being followed for our CS 151 course (as of 2019)
- Think Python - suitable for people with very limited programming experience, not very deep
- LearnXinYminutes - quick review once you are familiar with the basics
- Python.org tutorial - good for those with programming experience already
- Get Python installed on your computer - download the latest Python3 version at https://www.python.org/downloads/. Having python3 installed on your computer allows you to debug much quicker.
- Work on solving problems that are listed below.
- Cheat sheets - keep a cheat sheet for yourself of python syntax, built-in functions, etc. See below on this page for our model cheat sheets.
Running Python on ISU CS Systems
If you are using one of the CS lab computers or have a terminal open connected to the CS server, you can run python programs using one of the following methods.
Execute in the terminal Edit your python code with a text editor, and run it with the python3 or python command. For example,
cd ~ nano hello.py # and put some python code in hello.py then exit nano python3 hello.py
If you want to run the program with Python2, you would use the command
python rather than
python3. Note that we normally use Python3, so remember to run it as python3 and not python2.
Idle You can use the builtin Python3 graphical editor to edit your programs and also run them (only if you are on one of the lab computers or tunneling X). The command for Python3 is
idle3, and the command for Python2 is
idle. Note that we normally use idle3, so remember to run it as python3 and not idle2.
Running Python on Your Personal Computer
Install First make sure Python3 is installed - download from https://www.python.org/downloads/. Note that if you are using Linux then python3 is probably already installed; if not do an internet search for your Linux distribution and "install python3" (i.e., ubuntu install python). If you are using a Chromebook, then you should first get Linux (beta) installed (see []) and then you can follow instructions for installing python3 for ubuntu.
Open IDLE Once installed, you will run the program called IDLE, which is the graphical front-end for Python3. When you start IDLE, it shows you the Python3 console, where you can type your Python3 commands. Try typing in arithmetic expressions to make sure it is working. For example -
2 + 3 3 * 4 10 ** 3
Create a Python file We store python programs in text files.
- To create your first Python program file in IDLE, click on File and then New File.
print('Hello World!')in the file
- Click File and Save As. Name the file hello.py and save it in whichever directory you want to keep your python programs.
- Click Run and then Run Module. In the python console window you should see that your program ran.
- In your hello.py program, change it so that the code is the following -
print('Hello world.') print('Hello again.') print('Goodbye now.')
- Click Run and then Run Module to run the file again. In the console you should see that the program ran again.
That's it Now you are ready to learn more python from the sources linked on this page. You will put your code into python files, which are text files that end in ".py". You run the files inside of
Lists of Problems
Programming Assignments 1
Programming Assignments - Beginning 1 - start with trying to solve these problems. Each requires a different feature of the Python programming language, so solve these problems as you read through one of the tutorials or links above. Note that the page includes a link to repl.it that contains solutions to most of the problems. If you do not have Python installed on your computer, you can try it out at repl.it - click the logo at the top, then click "+ new repl", select Python and Create Repl.
Programming Assignments - Beginning 2 - another set of classic beginning programming exercises. Some of these will be more involved.
Once you can do some basic Python programming it is time to have some of your work checked. Hackerrank is a site where you can create an account and work on problems that will be checked if they are correct. Note that hackerrank has very strict rules for accepting correct solutions. Start with the basic problems to get a feel for what hackerrank expects.
If you are able to do most of the problems on the pages linked above, then you don't need us to give you lists of problems any more. You can pick problems to work through on your own. Some suggested places with problems are as follows.
These cheat sheets have the highlights of some of the basic information to memorize when you are in your first year of Python programming.