Python Starting

From Computer Science
Revision as of 16:40, 28 September 2022 by Jkinne (talk | contribs) (Reading and Tutorials)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Running Python Programs

To get started with Python programming, you need to be able to run the program. Here are some ways to get started...

Install Python

You can install python on your personal computer. You download from python.org/downloads, and it normally auto-detects your OS. Click the download button, install it, and open it open after it's installed. You can use the built-in text editor that is installed with Python (IDLE), or you can use a different text editor for editing your python files.

Python Online

There are various websites that provide an online Python environment that you can use in your web browser. Most of these are fine to use to get started. One that we are familiar with that you could try is repl.it.

Connect to the CS Server

The CS server has python installed. If you have an account for the CS systems (see CS Accounts and CS Lab Computers) then you can use this account to login to the CS server and run Python in the terminal. See CS Server - Terminal for how to connect to the CS server. Once you are logged into the server, you can run python in interactive mode by simply running: python3

To run a python program that is in your account on the server, you would run: python3 filename.py where filename.py is the name of the file you want to run. For example, you can do the following.

cd ~                                  # make sure you are in your home directory
cp /net/web/code/python/hello.py ./   # copy hello.py to your directory
python3 hello.py                      # run the program

Note that the python command might be running an older version of python (python2). You can tell by running this command: python --version. If this prints a version that is 2.something (e.g., 2.7.18), you should use the command python3 to make sure you are using the current version of python (as above).

Note that if you plan to use the terminal and CS server to do your development, then you will also need to be familiar with using one of the text editors that works in the terminal (Linux Terminal - Text Editors).

Reading and Tutorials

The following are good sources to read when starting out with python. If you are taking a course at ISU that uses python, the course might use one or more of these as required reading material.

  • Python.org tutorial - the official python documentation, good for those with programming experience already, or in a course where the instructor is guiding the class
  • w3schools Python - interactive tutorial where you can try out code in the browser
  • 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 2022)
  • Think Python - suitable for people with very limited programming experience, not very deep
  • LearnXinYminutes - quick review once you are familiar with the basics

Assignment 1

Your instructor might have you complete the following assignment to make sure you are all set with running Python code on the CS server.

First, make sure you can login to the CS server from your home computer. See CS Server - Terminal. For this assignment you will visit the CS help lab (either in person or remotely from home, see Unix Lab and Help) and demonstrate that you are able to edit and run python files on the CS server.

Once you are present at the CS help lab (either in person or online with a GA), you will do the following.

  1. Share your screen (if you are connecting online).
  2. Login to the CS server with your CS class account.
  3. Create a new directory named python_demo
  4. Go into the python_demo directory and start editing a file hello.py
  5. In the hello.py file, put a print statement to print "Hello World!", and save the file.
  6. In your terminal, run the hello.py program (by running python3 hello.py).
  7. Edit a file called count.py, and put code in it to print out the integers from 1 to 10. Save the file and demonstrate running it in the terminal.

That is it. You will have demonstrated that you can login to the CS server, edit python files, and run them. If you have any problems, the GA can help and give you a chance to start over again to demonstrate that you can do this.

Pass rating check You need to be able to do all of this on your own without help. If you have trouble and need some help from the GA, you can try again by starting the process over.

Note - the shared spreadsheet that GAs use for submitting information to Jeff Kinne's courses is this link, which should work only for the current term's GAs.