0% found this document useful (0 votes)
6 views24 pages

Module 1_ Hello World

The document is an introductory module for programming with Python, focusing on basic concepts such as what programming is, the importance of learning Python, and how to create simple programs. It includes detailed sessions on writing a 'Hello World' program, understanding numbers, variables, and data types, along with practical activities and exercises. The module aims to equip beginners with foundational skills in Python programming over a duration of two hours.

Uploaded by

217bey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views24 pages

Module 1_ Hello World

The document is an introductory module for programming with Python, focusing on basic concepts such as what programming is, the importance of learning Python, and how to create simple programs. It includes detailed sessions on writing a 'Hello World' program, understanding numbers, variables, and data types, along with practical activities and exercises. The module aims to equip beginners with foundational skills in Python programming over a duration of two hours.

Uploaded by

217bey
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

DirectEd Development

Foundation

Introduction to programming with Python

Module 1: Hello world


Table of contents

Module 1: Hello World 3

Overview 3

Learning Objectives 3

Requirements 3

Sessions 4
Session 1: An introduction to programming and Python 4
Session 2: Number, Variables, and Data Types 4

Session 1: An introduction to programming and Python 4


Activity 1: Reading 4
Topic 1: What is Programming? 5
Topic 2: Why Learn Python Programming? 6
1. Python Is Beginner-Friendly and Quite popular 6
2. Python Is Versatile 6
3. Python Developer Roles Are in High Demand 7
Activity 2: Hello World 7
Activity 3: Comments 9

Break Time 11

Session 2: Numbers, Variables, and Data Types 12


Activity 1: Numbers and Maths 12
Activity 2: variables, what are they? 16
Activity 3: Python Data Types 20

Summary 23

Next Steps 24

1
Module 1: Hello World

Overview
Welcome to the first Module where you will start writing Python code maybe for the
first time in your lives, Here we will learn about what programming languages are,
why we need them, and also why we are learning Python.

Duration:- 2 hrs.

Learning Objectives
After completing this module you will be able to:

● Explain what computer programming is and why it is important to learn


Python.
● Create and run Python programs that accept input from the user and/or
display output using Jupyter notebook along with descriptive comments.
● Use Python’s arithmetic operators to perform addition, subtraction,
multiplication, division, and so on.
● Create Python variables that belong to different Data types.

Requirements
● You must complete module 0: introduction before working on the activities we
have put here.

2
Sessions
Session 1: An introduction to programming and Python

Duration: 50 mins.

● Activity 1: Reading
○ What is programming?
○ Why learn Python Programming?
● Activity 2: Your first program, “Hello World”
● Activity 3: Comments

Session 2: Number, Variables, and Data Types

Duration: 50 mins.

● Activity 1: Numbers and Math in Python


● Activity 2: Variables, What are they?
● Activity 3: Python Data Types

Session 1: An introduction to
programming and Python

Activity 1: Reading

During the next 5 days, you will be creating computer programs using Python, but
before you do you must understand what programming is and why we are learning
Python.

Duration: 15 mins.

Goal: To understand computer programming and the reason why one should learn
Python.

3
Instructions: Read Topic 1 and Topic 2 found below.

Topic 1: What is Programming?

Computer programs are incredibly powerful tools that can be used in a variety of
ways. They can store and process large amounts of data quickly and accurately,
perform complex calculations, and create and modify documents. This makes them
invaluable tools in today's world.

Computer programs can also be programmed to do tasks that would ordinarily take a
human much longer to complete. For example, a computer program can be
programmed to automatically sort through hundreds of emails and organize them
into categories. This can save a great deal of time and effort, as well as reduce the
risk of human error.

Computer programs are also incredibly powerful when it comes to performing


complex calculations. For example, a computer program can quickly calculate the
square root of a number or determine the probability of a particular event occurring.
This can be incredibly useful for scientists, mathematicians, and other professionals
who need to perform complex calculations.

In simple words, a computer program is like a recipe for a delicious meal. Just like a
recipe a computer program is a set of instructions that tell a computer what to do.
The instructions are written in a language that the computer can understand, like a
set of instructions written in English. The instructions tell the computer what to do
step-by-step, just like a recipe tells a cook what to do step-by-step. The instructions
can be as simple as telling the computer to print out a message, or as complex as
telling the computer to create a game. The instructions can also be used to create
websites, apps, and other software. Just like a recipe, the instructions need to be
written in the right order and with the right structure for the computer to understand
them. Once the instructions are written, the computer can follow them and do what it
is told.

Computer programming is the act of writing the step-by-step instructions that make
up a computer program and to write computer programs we use programming
languages, Although many languages share similarities, each has its syntax. Syntax

4
in a programming language can be compared to grammar in the English language.
Just as grammar is the set of rules that govern how words are used to form
sentences, Syntax is the set of rules that govern how programming language
instructions are written. Once a programmer learns the language's rules, syntax, and
structure, they write the source code in a text editor. Then, the programmer often
translates the code into machine language that can be understood by the computer
using a program called a compiler or an interpreter.

During the next 5 days, you will be learning a programming language called Python
which is easy to learn and can be used to write all sorts of computer programs. you
can use Python to build games, online tools, and websites. Python looks like a
mixture of recognizable words and characters, so it can be easily read and
understood by humans.

Topic 2: Why Learn Python Programming?

Python is a general-purpose programming language, which means that it can be


used for a wide variety of tasks such as building software and websites, data
analysis and so much more. Though it’s been around for 30 years, it has recently
become one of the most popular programming languages, and its popularity
continues to grow. Here are some reasons why you should learn Python:

1. Python Is Beginner-Friendly and Quite popular

Python is an excellent place to begin if you’re new to coding. It features simple


English syntax and is designed to be concise and easy to read which makes it
accessible to first-time coders. When it comes to Python’s popularity and growth
rate, the numbers don’t lie. Python is the most-searched programming language on
the internet and that doesn’t look like it will be changing any time soon.

2. Python Is Versatile

Part of this acclaim is due to Python’s usefulness in the world of data science; as
fields like machine learning, data modeling, and AI grow, so too does the demand for
Python-related skills. You can use Python for both small and complex tasks, and it is
used across many different industries from data science and software engineering to

5
environments like mobile app development, artificial intelligence, and machine
learning.

3. Python Developer Roles Are in High Demand

Many major companies including DropBox, Netflix, and Facebook use Python.
According to Indeed, Python developers earn an average salary of $108,391,
Statista also named Python the third most in-demand language by recruiters in 2022.

Exercise

● Go to google classroom and take Programming quiz 1.

Activity 2: Hello World

The journey of a thousand miles begins with the first step, well in our case creating a
computer program with thousands of lines of code starts with writing the first line so
get ready for some hands-on Python practice don’t worry if things get a little
confusing this is your first program after all.

Duration: 15 mins.

Goal: To create and run your first Python program using Jupyter notebook.

Instructions:

● Step 1: Go to Pydroid and run Jupyter notebook.


● Step 2: Create a new file titled ex1.
● Step 3: Inside ex1 Write the code found on top of the next page:

6
Reminder: Do not copy-paste code.

● Step 4: Once finished, run your code and check if you have errors.

○ In case of an error compare the code you have with the code that is
provided to you or Google the error code displayed by Jupyter and try
to find a solution.
● If you need more help check out the video titled ex1 found along with this
document in google classroom.

Note:
○ Point 1: The atom text editor used in the video corresponds to your
Jupyter notebook.
○ Point 2: Use Jupyter to run and test your code.

Notes:

The print() function in Python is used to display a specified message on the screen.

Study Drill:

The Study Drills contain things you must do before moving on to the next section. If
at any point you find yourself getting stuck revise your code and also try to use
google to your advantage.

7
For this exercise, try these things:

1. Make your script print another line.


2. Make your script print only one of the lines.
3. Put a # (octothorpe) character at the beginning of a line. What did it do? Try to
find out what this character does.
4. Once you have finished the study drill submit the file you have worked on to
the respective assignment title in google classroom.

Activity 3: Comments

Duration: 20 mins.

Goal: To create a program that contains comments.

Topic: What is a comment?

Comments in Python are lines of text that are not run as part of the program. They
are used to explain what the code is doing and to make the code easier to read and
understand.

Comments are useful when you are writing code that is complex or that you may
need to refer back to later. They can help you remember what the code is doing and
make it easier to debug if something goes wrong.

8
Comments can also be used to disable a line of code temporarily. This is useful if
you want to test something without running the entire program. For example, if you
wanted to test a certain line of code without running the rest of the program, you
could add a comment like this:

Instructions:

● Step 1: Go to Pydroid and run Jupyter notebook.


● Step 2: Create a new Jupyter file titled ex2.
● Step 3: Write the code that is found above in the explanation section.
● Step 4: Run your code and Evaluate your output.
● If you need more help check out the video with the title ex2 found along with
this document in google classroom.

Note:

○ Point 1: The atom text editor used in the video corresponds to your
Jupyter notebook.
○ Point 2: Use Jupyter to run and test your code.

Study Drills:

● Find out if you were right about what the # character does and make sure you
know what it's called (octothorpe or pound character).
● Take your ex2.py file and review each line going backward. Start at the last
line, and check each word in reverse against what you should have typed.
● Did you find more mistakes? Fix them.
● Please read what you typed above out loud, including saying each character
by its name. Did you find more mistakes? Fix them.
● Once you have finished the study drill submit the file you have worked on to
the respective assignment title in google classroom.

9
Common student questions:

● Why does the # in print("Hi # there.") not get ignored?

The # in that code is inside a string used to store text information. Strings are
surrounded by either single quotation marks or double quotation marks. , so the #
will be put into the string until the ending " character is hit. Pound characters in a
string are just considered characters, not comments.

● How do I comment out multiple lines?

Put a # in front of each one.

● I can't figure out how to type a # character on my country's keyboard. How do


I do that?

Some countries use the Alt key and combinations of other keys to print
characters foreign to their language. You'll have to look online in a search
engine to see how to type it.

● Why do I have to read code backward?

It's a trick to make your brain not attach meaning to each part of the code, and
doing that makes you process each piece exactly. This catches errors and is a
handy error-checking technique.

Break Time
Take a 10-minute break and come back for session two.

10
Session 2: Numbers, Variables, and Data
Types
Activity 1: Numbers and Maths

Duration: 15 mins.

Goal: To create a program that uses the above math symbols for calculations

Topic: What are Python maths symbols?

Maths is everywhere, from the basic operations of addition, subtraction,


multiplication, and division to more advanced equations that help us explain
phenomena in the natural world. in programming, math is used to do many things
from counting the number of likes on a social media post to making calculations that
guide rocket ships. In Python, we use different math symbols to perform such
calculations.

Here is a list of math symbols that Python supports:

Math symbol Name Description Example


(Operator)

+ Addition Adds numbers. x+y


5+3

- Subtraction Subtracts the number on the right from x-y


the number on the left. 5-3

* Multiplication Multiplies numbers. x*y


5*3

/ Division Divides the first number by the second x/y


one. 4/2

11
Math symbol Name Description Example
(Operator)

% Modulus Finds the remainder of an expression. x%y


5%3

> Greater than Checks if a number is greater than x>y


another number. if correct it returns true 5>3
else it returns false.

< Less than Checks if a number is less than another x<y


number. if correct it returns true else it 5<3
returns false.

>= Greater than or Checks if a number is greater than or x >= y


equal to equal to another number. if correct it 5>=3
returns true else it returns false.

<= Less than or Checks if a number is less than or equal x <= y


equal to to another number. if correct it returns 5 <=3
true else it returns false.

The symbols found in the above table are also known as operators, Python has
different kinds of operators that it uses to perform various tasks. you will learn about
them more as you progress through this course.

Instructions:

● Step 1: Go to Pydroid and run Jupyter notebook.


● Step 2: Create a new Jupyter file titled ex3
● Step 3: write the code found at the top of the next page in your Jupyter file.

12
● Step 4: Run and evaluate your code.
Note:
○ Analyze your code line by line and say what it does in your head, This
will help you understand the code better.
■ For example, you could say: “Line 1 displays a text that reads I

13
● If you need more help check out the video titled ex3 found along with this
document in google classroom.

Note:

○ Point 1: The atom text editor used in the video corresponds to your
Jupyter notebook.
○ Point 2: Use Jupyter to run and test your code.

Study Drills:

1. write a comment using the # symbol above each line of code explaining what
it does.

Note:

■ Point 1: If you have trouble understanding what each symbol


does refer to the table found above to check what a symbol
does.
■ Point 2: Make sure you write a comment for all the lines
because this is done deliberately to help you learn by yourself
and develop your analytical skills. which is one of the most
important skills a good programmer can have.
2. On the last line of the ex3 file, write Python code that adds the ages of your
parents and displays it.

Note: If you don’t know the age of your parents simply try to guess.

3. In your google search bar type “Arithmetic operators in Python“ and try to
learn what they are, afterwards check which Math Symbols/operators belong
to this category. (This task will not be submitted but you must take notes for
yourself).
4. Once you have finished the study drill submit the Jupyter file you have worked
on to the respective assignment title in google classroom.

14
Common Student Questions

● Why is the % character a "modulus" and not a "percent"?

Mostly that's just how the designers chose to use that symbol. In normal writing, you
are correct to read it as a "percent." In programming, this calculation is typically done
with simple division and the / operator. The % modulus is a different operation that
just happens to use the % symbol.

● How does % work?

Another way to say it is, "X divided by Y with J remaining." For example, "100 divided
by 16 with 4 remaining." The result of % is the J part or the remaining part.

● What is the order of operations?

There is an acronym called PEMDAS which stands for Parentheses Exponents


Multiplication Division Addition Subtraction. That's the order Python follows as well.
The mistake people make with PEMDAS is to think this is a strict order, as in "Do P,
then E, then M, then D, then A, then S."The actual order is you do the multiplication
and division (M&D) in one step, from left to right, then you do the addition and
subtraction in one step from left to right. So, you could rewrite PEMDAS as
PE(M&D)(A&S).

Activity 2: variables, what are they?

Duration: 10 mins.

Goal: To create and run a Python program that contains variables on Jupyter
notebook.

Topic: What is a variable?

Variables are like little containers that hold information. Think of them like a box
where you can put things inside. For example, if you wanted to remember a person's
age, you could put that age inside a variable called "age", and then you can always
look inside the box to see what age is stored inside. Variables are very useful for

15
computer programs because they help keep track of lots of different pieces of
information.

Creating variables:

Python has no command for declaring a variable. A variable is created the moment
you first assign a value to it but Python still has specific rules as to how you can
name variables which are as follows:

● A variable name must start with a letter or the underscore character


● A variable name cannot start with a number
● A variable name can only contain alpha-numeric characters and underscores
(A-z, 0-9, and _ )
● Variable names are case-sensitive (age, Age, and AGE, are three different
variables)

Here is how you can create variables in Python:

16
A few things about the code above:

● The first 8 lines of code create different variables.


● The _ in space_in_a_car is called an underscore character. We use this
character a lot to put an imaginary space between words in variable names.

Instructions:

● Step 1: Go to Pydroid and run Jupyter notebook.


● Step 2: Create a new Jupyter file titled ex4
● Step 3: Write the code found above inside the file.
● Step 4: Run and test your code.
Note:
○ Point 1: Try to determine how many variables your code has.
○ Point 2: Try to figure out the purpose of the single equal sign in your
code. (If you get stuck consider using google ).
● If you need more help check out the video titled ex4 found along with this
document in google classroom.
Note:
○ Point 1: The atom text editor used in the video corresponds to your
Jupyter notebook.
○ Point 2: Use Jupyter to run and test your code.

Study Drills:

1. Inside ex4 write a comment above each line that explains what it does. For
Example, your comment above line 1 should read.

#Creates a variable called cars and assigns it a value of 100.

2. Inside ex4 create a variable called age that stores your age.
3. Inside ex4 create a variable called age that stores your age.
4. Once you have finished the study drill submit the file you have worked on to
the respective assignment title in google classroom.

17
Common Student Questions

● What is the = (single equal sign)?


The single equal sign is called the assignment operator, it assigns the value
on the right to a variable on the left, for example, x=4 assigns 4 to the variable
x.
● Can we write x=100 instead of x = 100?

You can, but it's bad form. You should add space around operators like this so
that it's easier to read.

● Can I make a variable like this: 1 = “hello”?


No, 1 is not a valid variable name because variable names cannot start with
or be a number.
● What do you mean by "read the file backward"?

Very simple. Imagine you have a file with 16 lines of code in it. Start at line 16,
and compare it to my file at line 16. Then do it again for 15, and so on until
you've read the whole file backward.

18
Activity 3: Python Data Types

Duration: 20 mins.

Goal: To create a Python program that contains variables of number, text, and
Boolean Data Types

Topic: what are data types?

In a computer program, you will be working with different types of data such as
numbers, text, and so on. we call these Data types which are different kinds of
containers that can hold different types of information. For example, a string is like a
box that can hold words, and a number is like a box that holds numbers. When we
write a program, it helps to know what kind of information we will be using so that our
program can work correctly. When you tell someone your name, your age, or what
you had for breakfast, each of those pieces of information is a different data type.

Variables can store data of different types, and different types can do different things.
Python has the following data types built-in by default, in these categories:

Python also has more complex Data Types, but for now, knowing the ones
mentioned above is enough.

19
Note: In Python, the data type is set when you assign a value to a variable, Here is a
code containing the different data types:

Instructions:

● Step 1: Create a Jupyter file named ex5.


● Step 2: Write the code found above inside the file.
● Step 3: Run and evaluate your code line by line, try to figure out what each
line of code does.

20
Study Drills: These drills are to be performed on the ex5 file you just created.

1. Go to line 9 and use the print method to display the rest personal information.
Note:

Follow the same format used on line 8 to display the others.

2. For the following two tasks refer to line 11 to see the type of comment you
should add.
1. Add a comment on line 17 that explains what the code on line 18 does.
2. Add a comment on line 20 that explains what the code on line 21 does.
3. To the ex5 file add a variable called my_friend_name and assign it the name
of your friend, After that display the name of your friend as an output.
4. Create a variable named my_friend_age and assign it the age of your friend,
use the print statement to display the sum of my_age and my_friend_age
Note:

If you don’t remember how to add two numbers go back to Activity 1


and revise the code for arithmetic operators.

5. Google what “concatenating a string means” and try to explain it in your own
words using a flash card. ( you don’t need to submit this task).
6. Have you figured out what the type() method does? if not make sure you
check online what it does before moving on to the next activity.
7. Once you have finished the study drill submit the file you have worked on
under the respective assignment title in google classroom.

21
Common student questions

● What is concatenation?

String concatenation is a fun way to join two strings together. It's like putting
two pieces of a puzzle together! You can take two strings and put them
together to make one longer and bigger string. For example, if you have two
strings that say "hello" and "world", you can concatenate them together to
make a new string that says "hello world". Concatenation is performed using
either a comma ( , ) or a plus (+) symbol.

● Why do you put (single quotes) around some strings and double quotes
on others?

Mostly it's because of style, strings can be created using either single quotes
or double quotes.

Summary
Well Done! You have made it to the end of the module, here is what we have done
so far:

● You learned what programming and programming languages are.


● You understood the importance of studying Python.
● You created your first Python program on Jupyter.
● You used the print statement to display text on the screen.
● You learned how to create comments in Python.
● You learned how to perform calculations using maths symbols.
● You learned how to create variables in Python.
● You learned about the different data types Python supports.

22
Next Steps
1. Fill in the TypeForm https://96q5m6wcmma.typeform.com/to/WJA2BHqG
2. Go to google classroom and download the Module titled Module 2:

23

You might also like