Part 1 - Intro to Python

Python Official Website

Program Arcade Games Website

This section will introduce the user to the very basics of programming and using the Python language.

There is a FAQ section for most Topics. It contains helpful information.

Back to main page

You must have Python downloaded and installed from the official Python website if you are working from home.

Make sure you know how to use IDLE or PyCharm to create Python projects.

I recommend using PyCharm as it has many useful features. Download the Community Edition for free and install it from here:

https://www.jetbrains.com/pycharm/

I have created a tutorial on how to create a new project and run it in PyCharm here:

https://sites.google.com/gotvdsb.ca/aldworth/home/ics-3u/using-pycharm

What to Do/Hand In?

1 - Read through and complete the Part 1 - Intro to Python handout.

2 - Read through and complete Chapter 1 - Create a Custom Calculator section of ProgramArcadeGames.com

    • Read sections 1.2, 1.4 - 1.10.

    • It is important to read everything in each section, there is a lot of important information contained there.

3 - Do the online Multiple Choice Quiz.

4 - Complete and Hand in worksheet for Part B.

  • Make sure that you have complete all of the readings and done the online quiz before doing the worksheet.

5 - Hand in three programs for Part C. You may submit one file with all parts. Be sure to include your name in a comment. Also, use comments to indicate what parts of your programs are for what questions in the exercise.

Submit:

  1. Worksheet for Part B

  2. Three programs for Part C.

    • Summer Pay, Payroll and Formula

    • Make sure to put your name in a comment at the top of your program!

    • Make sure you are storing values in variables.

    • Provide appropriate prompts when asking for information, and descriptive feedback, explaining output.

Part1 - Intro to Python.pdf

Hints and FAQs

*Do not just read through tutorials.

When you are given sample code, run it. See what happens. Experiment with it. Make small changes and try to predict that will happen.

This will help you learn and remember concepts that you will use later on.

The first part of this section uses the Python interactive shell, and you are not actually writing a program. Here you can test individual lines of code and see what happens. Basically you type individual commands and it processes them when you press Enter so you can see what happens. A 'program' is when you type a number of commands in a file, and at a later time they are all run at once.

When you get to the "Writing Programs in IDLE's File Editor" part of the tutorial, you will actually name a Python program. Make sure that you go to the File menu at the top of the shell and select New File. Here is where you will actually write and save your programs.

Q: When I try to do calculations with a number from the keyboard, why is the math is wrong?

A: The most likely answer is that you are not converting what the user typed into a numerical format. Some of the mathematical operators mean different things when they are used on strings(sequences of characters that may or may not be numeric) than on numbers. (It is also possible that you have an error with the logic of your mathematical expression such as order of operations)

When you use the input("...") function, what is typed by the user is stored in the computer as a string of individual characters. Each character has it's own value associated it when it is stored in the computer called an ASCII value. For example, a capital 'A' is stored as the number 65, while a lower case 'a' is stored as a 97.

The character for the number '4' is stored in the computer as '52'. If you want to do math with a number that a user enters, you must convert it to the appropriate numerical type so that it is actually stored as a number.

    • int : use this numeric type if you do not need decimal precision

    • float : use this numeric type if you need decimal precision

You can convert values to numeric type before you use them, or as you use them. Here are some examples:

Conversion before data is stored (data will be stored as a numeric variable):

price = float(input("Please enter the price of the item")) #the variable 'price' stores a floating decimal point number


tax = price * 0.13

OR

Conversion to numeric type inside the expression:

price = input("Please enter the price of the item")

#the variable price contains a sequence of characters


tax = float(price) * 0.13

#we must convert the string stored in price to a floating #point number before we can perform calculations with it