G11 CS WK8 Introduction to Python
G11 CS WK8 Introduction to Python
WEEK 8
AGENDA:
1. What is Python (Introduction).
2. Python main usability.
3. How to download and install python?
4. Python Compartments.
5. Print, Print String, Variables, Expression and Variables examples.
6. Values, Integers, Floats, Strings and Booleans.
7. Exercise.
OBJECTIVES
IT COULD BE
USED BY
PC & MAC
SYSTEMS
PYTHON MAIN USABILITY:
Python programmers can earn tons of money yearly depend where they are
going to use the program, first, you need to define which field are you going
to use Python in, here are some examples below;
1. Automation: Such as sending out, replying to, and sorting emails. Filling out PDFs and Excel
files. Sending HTTP requests. Converting image files.
2. Artificial Intelligence (AI): refers to a computer's or a robot's ability to perform jobs normally
performed by humans.
3. Application: Open-source high-level language, general-purpose programming language that
combines object-oriented, structural, and functional programming capabilities.
4. Web: It uses a shared backend logic, which means the code runs on the server (could be
your computer) rather than in the browser.
Identify the location you wish to save your project in and change the last name to Seniors_2024.
TIME TO
START
CODING
PYTHON COMPARTMENTS
Python usually is using interpreter system, that means the file getting executed
automatically once you start writing your first line in the project, unlike compiler
where you must hit run and redo your work anytime you want to apply any changes.
PRINT:
First line: Add print (‘ ‘ ) to apply values on screen. Note you can use a single quote or
double quoting, but for this method single quote in preferable.
In between the quotes start writing your name. print (‘Your Name’)
Anytime you wish to see the results, go to Run tab Run. Now you can choose Python
program.
You should see a small window below has your print on screen.
Now let’s draw a smiley face by typing, print (‘O O’). Double space between the eyes.
Then in the second line type, print (‘ I’). Make sure it’s aligned between the eyes.
Third line type, print (‘ U’). Make sure they are all aligned in the middle of the first
line (eyes).
Use spaces to align the values correctly.
Hit Run.
APPLYING PRINT STRING:
A string is a programming term which means a series of characters that follow each other
within the same value.
A quick trick, add a value then add space + asterisk (*) and a number after the quotation, it
will multiply the value as many as the number is stating. For example;
Print space Open bracket one quotation Asterisk one quotation space multiply (*)
space Number (10)
print (‘*’ * 10)
So in the above variable we have multiplied the value 10 times to appear in the screen as a
series of the same value
This type of coding called an Expression. TAKE NOTES IN YOUR BINDER PLEASE
EXPRESSION:
Expression is a piece of code that produces a value. So, when
Python interprets, it executes the line by evaluating the code that is
added between the parenthesis/brackets.
AFTER EVALUATION =
TAKE NOTES IN YOUR
BINDER PLEASE
VARIABLES:
Variable means being able to change inputs on the go.
Variables are used to temporarily store data in computers memory. For Example;
price = 10
rating = 4.5
course_name = CS Python Project
is_published = True
We use comments to add notes to our code. Good comments explain the hows and whys,
not what the code does. That should be reflected in the code itself. We use comments to
add reminders to yourself or other developers, or also explain your assumptions and the
reasons you’ve written code in a certain way.
Type price = 10 (Python will start memorizing the number and will attach it this price label in its
memory location).
Now use print to enter value. (Make sure you don’t add quotations at this point as we are
entering variables not values…
Enter print = (price) Run
Variables
+ Values
=
Output
VARIABLES EXAMPLE:
Now as you see number 10 is stored in the memory and converted to binary (Low-Level
Language)
Let’s take the program to the next level!
Let’s add in the second line price = 20 this time and we will keep the price = 10 in the first
line and print(price) at the last line. WHAT HAPPENED !!!
As we know Python is an interpreter program so any input in any line will be automatically
updated on the screen/terminal.
So, adding another variable after another is called Re-Set, therefore, the new line will
TAKE NOTES IN YOUR BINDER PLEASE
reset the first line, and the number now will appear as the new input.
VARIABLES EXAMPLE:
So, the output put will appear as 20 now.
New output
CS
STUDENTS
WILL BE
WHAAAT?!
LIKE
VARIABLES INTEGER VS FLOATS:
Integer are the number that are written in python without a decimal added into them.
Numbers with a decimal point can be used in other variables such as rate.
Giving an example of decimal numbers, lets replace line 2 with; rating = 4.8…
1. price = 10 Integers
AS A lowercase LETTERS
WE ARE FINALLY
DONE!