0% found this document useful (0 votes)
7 views

Python Class 4

Uploaded by

aneeq fayyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Python Class 4

Uploaded by

aneeq fayyaz
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Python For Kids

Class 2
• Arithmetic Operations:
Introduction of basic arithmetic operators (+, -, *, /, %) and their usage in
Python.
Conditional Statements (if-else):
• Python supports the usual logical conditions from mathematics:
• Equals: a == b
• Not Equals: a != b
• Less than: a < b
• Less than or equal to: a <= b
• Greater than: a > b
• Greater than or equal to: a >= b
Dictionary
• Dictionaries are used to store data values in key:value pairs.
• A dictionary is a collection which is ordered*, changeable and do not allow
duplicates.
• Dictionaries are written with curly brackets, and have keys and values:
• Python Collection Data Types
• There are four collection data types in the Python programming
language:
• List is a collection which is ordered and changeable. Allows duplicate
members.
• Tuple is a collection which is ordered and unchangeable. Allows
duplicate members.
• Set is a collection which is unordered, unchangeable*, and unindexed.
No duplicate members.
• Dictionary is a collection which is ordered** and changeable. No
duplicate members.

HW: Go and search the codes for sets and tuples


Sets Tuples
• A set is a collection which • Tuples are used to store multiple
is unordered, unchangeable*, items in a single variable.
and unindexed. • A tuple is a collection which is ordered
• Sets are written with curly and unchangeable.
brackets. • Tuples are written with round
• Sets are unordered, so you cannot brackets.
be sure in which order the items • Allow Duplicates
will appear.
• Duplicates Not Allowed
• Python Loops
• Python has two primitive loop commands:
• while loops
• for loops

The while Loop


• While loops are like little helpers that keep doing something as long as
a condition is true.
• We give them a condition to check, and they will repeat an action until
the condition is no longer true.
• For example, we can use a while loop to keep playing a game until we
win or to keep counting as long as it's daytime.
• With the while loop we can execute a set of statements as long as a condition is
true.
• In python, a while loop is used to execute a block of statements repeatedly until
a given condition is satisfied. And when the condition becomes false, the line
immediately after the loop in the program is executed.
Python For Loops
• For loops are like magic wands that can repeat actions
for us. They save us from doing repetitive tasks.
• We can tell the for loop how many times we want the
action to be repeated, and it will do it for us
automatically.
• A for loop is used for iterating over a sequence (that
is either a list, a tuple, a dictionary, a set, or a string).
Challenges
• Challenge 1: Write a program that takes a number as input and checks
whether it is greater than 10 or not.
• Challenge 2: Write a program that takes a number as input and checks
whether it is even or odd.
• Challenge 3: Write a program that prints the multiplication table of a
number entered by the user.
For loop Example:
Solution to the challenges
Challenge 2: Challenge 2:
Printing pyramids using loops

• Half Pyramid: • Full pyramid:


Functions
• Functions are like special helpers that perform specific tasks. They
make our code organized and reusable.
• We can create our own functions by giving them a name and telling
them what to do. We can use these functions whenever we want.
• For example, we can create a function called "greet" that says "Hello,
welcome!" every time we call it.
Function Parameters and Return Values:
• Function parameters are like special inputs that we give to a function.
They help the function know what to work with.
• We can pass different values to functions through parameters to get
different results.
• For example, we can create a function called "add_numbers" that takes
two numbers as inputs and gives us their sum as a result.

You might also like