/python

A python tutorial to get you comfortable with python.

Primary LanguagePython

python

1 What is python?

Python is a programming language. You write code files, and then you can run the code files, and they'll do what you told them to do. This tutorial will teach you how to use python in a variety of situations. If this is your first programming language, hopefully this is a gateway to a new way of understanding the world!

Two ways to play: Install or Interpret

There are two ways to approach this tutorial set. If you have time, we recommend installing python on your own computer; otherwise read below for an online interpeter.

Installing python on your computer

  1. Go to the python website: https://www.python.org/downloads/
  2. Follow the python install instructions. If you are asked whether to "Add Python to PATH", press Yes or check the checkbox.
  3. Copy this set of code files, by pressing the green button on the upper right ("CODE") and download this code as a zip file. (Or, if you know how to use git, you can use that too.)
  4. Download an editing tool e.g. visual studio code (https://code.visualstudio.com/). This will highlight the code and make it so much easier to read.
  5. Open each file with your editing tool (use right click->open with or otherwise).
  6. Read each file and the included comments. When you're ready to run your program:
    1. [WINDOWS] Open a console window by pressing shift+right click in the file explorer where the code file is located.
    2. Press Open Powershell Window Here
    3. In the blue window that pops up, type in python the_code_file.py, then press enter.

Using an interpreter

Alternatively, if you don't have much room on your computer, you can use an online python environment. We recommend https://repl.it/languages/python3. Then, instead of downloading the files here, you can copy the entire contents of the file into the window on the left, and press the run button when you're ready.

Alright, time to get started! The files in this repository include:

  1. 1_helloworld.py
  2. 2_variables.py
  3. 3_types.py
  4. 4_input.py
  5. 5_control.py
  6. 6_lists.py
  7. 7_dictionaries.py
  8. 8_functions.py
  9. 9_classes.py
  10. 10_libraries.py

If you have any edits to suggest, please email usydrobotics@gmail.com :)

Challenges

Once you're done looking over all the files, try some of these challenges!

  • A program that outputs triangular numbers
  • A program that outputs prime numbers
  • A program that simulates a projectile's motion
  • A program that tells you the current system time

Happy coding!

Proof of work, session 1

Write a program called sayMyName.py that prints out your name N times, where N is the first 2 digits of your SID. For example, if your SID is 432422232 and your name is Kimi Nonawa, then you would print:

Kimi Nonawa
Kimi Nonawa
Kimi Nonawa
... (repeat 43 times total)
Kimi Nonawa