SlideShare a Scribd company logo
Introduction to 
Programming with 
Python – Class 1 
SYED FARJAD ZIA ZAIDI
Class Objectives 
Class Objective 
Review variables, statements, expressions, functions, algorithms and technical 
terms. 
Understanding Flow Control. 
Write a simple program that performs addition, subtraction, multiplication and 
division using Functions.
Class Material 
•Chapter 1, 2, 3 - Python 
for Informatics: Exploring 
Information 
Reading 
Assignment •Rock, Paper, Scissors
Variables 
 Definition: 
A named piece of memory that can store a value. 
 Statement: 
A statement written in a programming language stores a value in a variable. 
Example: 
X = 5 
Y = 1 
 Expression: 
A variable that has a value can be used in an expression. 
Example: 
X = X + 4 
Y = X + 1
Rules for defining a Variable: 
 Names must start with a letter or _. 
 Names must contain only letters, digits, and _.
Questions?
Functions 
 Definition: 
A function is a block of organized, reusable code that is used to perform 
some action. 
 Defining a function: 
You can define a function in Python using the Keyword ‘def’. 
 General Form of Function: 
def function_name(parameters): 
body 
Example: 
def MyFirstFunction(): 
print “This is my first function in Python Programming Language”
Defining Functions 
You can define functions to provide the required functionality. Here 
are simple rules to define a function in Python. 
 Function blocks begin with the keyword ‘def’ followed by the 
function name and parentheses ‘( )’ . 
Example: 
def MyFirstFunction(): 
 Any input parameters or arguments should be placed within these 
parentheses. You can also define parameters inside these 
parentheses. 
Example: 
def MySecondFunction(passedInput):
Defining Functions 
 The first statement of a function can be an optional statement - the 
documentation string of the function or docstring. 
Example: 
def MyFirstFunction(): 
“””This is the 'docstring' which defines 
the function for other programmers to 
understand easily””” 
 The code block within every function starts with a colon (:) and is 
indented.
Defining Functions 
 The statement return [expression] exits a function, optionally passing 
back an expression to the caller. A return statement with no 
arguments is the same as return None. 
 General Form of Return Statement: 
return [expression] 
Example: 
def MyFunction(): 
“”“A function that returns a message””” 
return “This is a function that returns a message”
Calling a function 
 Function calls are expressions and the result can be stored in a 
variable. The general form of a function call: 
function_name(arguments) 
Example: 
MyFirstFunction() 
MySecondFunction(“Input Parameter”)
Questions?
Source Code vs Object Code 
Source Code Object Code 
Source Code is a text file version of 
a computer program or software that 
contains instructions that the 
computer follows to do something 
Object code, or sometimes an object 
module, is what a 
computer compiler produces 
Source code is written in 
a programming language which a 
human can read and change 
In a general sense object code is a 
sequence of statements or instructions 
in a computer language, usually 
a machine code language (i.e., 1's 
and 0's) 
Most source code is compiled when it 
is finished 
Object code is the resulting code 
after compiling source code
Compiler 
 A compiler is a computer program (or set of programs) that 
transforms source code written in a programming language (the 
source language) into another computer language (the target 
language, often having a binary form known as object code). The 
most common reason for wanting to transform source code is to 
create an executable program.
Questions?
Flow Control of the Program 
 Selection (If/Else) 
 Repetition (Loops)
Conditional Execution 
 In order to write useful programs, we almost always need to check 
some conditions and change the program accordingly. Conditional 
Statements gives us this ability. The simplest form is if statement. 
 General Form: 
if [expression1]: 
body1 
elif [expression2]: 
body2 
else: 
bodyN
Python Comparison Operators 
Operator Description 
== Checks if the value of two operands are equal or not, if yes 
then condition becomes true. 
!= Checks if the value of two operands are equal or not, if 
values are not equal then condition becomes true. 
< Checks if the value of left operand is less than the value of right 
operand, if yes then condition becomes true. 
> Checks if the value of left operand is greater than the value of right 
operand, if yes then condition becomes true. 
>= Checks if the value of left operand is greater than or equal 
to the value of right operand, if yes then condition becomes 
true. 
<= Checks if the value of left operand is less than or equal to 
the value of right operand, if yes then condition becomes 
true.
Python Logical Operators 
Operator Description 
and Called Logical AND operator. If both the operands are 
true then then condition becomes true. 
or Called Logical OR Operator. If any of the two operands 
are non zero then then condition becomes true. 
not Called Logical NOT Operator. Use to reverses the logical 
state of its operand. If a condition is true then Logical NOT 
operator will make false.
Questions?
Simple Calculator 
 Definition: 
A calculator is a machine which allows people to do math operations 
more easily. For example, most calculators will add, subtract, multiply, and 
divide. 
 Instructions for writing the Program: 
 There should be 4 functions in your program: 
 Add(number1, number2) 
 Subtract(number1, number2) 
 Multiply(number1, number2) 
 Divide(number1, number2) 
 The template for the program can be accessed here: 
http://www.codeskulptor.org/#user37_44o34rWsnC_18.py
Questions?
Rock Paper Scissors – 1st Mini- 
Project 
Rock-paper-scissors is a hand game that is played by two people. The 
players count to three in unison and simultaneously "throw” one of 
three hand signals that correspond to rock, paper or scissors. The 
winner is determined by the rules: 
 Rock smashes scissors 
 Scissors cuts paper 
 Paper covers rock
Instruction 
 In our first mini-project, we will build a Python function rps(name) 
that takes as input the string name, which is one of "rock", "paper", 
"scissors“. The function then simulates playing a round of rock-paper-scissors 
by calling a helper function gen_random_num() that 
generate own random choice from these alternatives and then 
determining the winner using simple if / else statements. 
 The mini-project template is here: 
http://www.codeskulptor.org/#user37_HJPdXx35jy_0.py
Example runs 
Player chooses rock 
Computer chooses scissors 
Player wins! 
Player chooses paper 
Computer chooses scissors 
Computer wins! 
Player chooses scissors 
Computer chooses paper 
Player wins!
Questions?

More Related Content

PPTX
Introduction To Programming with Python Lecture 2
PPTX
Introduction To Programming with Python-3
PDF
Lesson 02 python keywords and identifiers
PPTX
Python second ppt
PDF
Lesson 03 python statement, indentation and comments
PDF
Python Objects
PDF
Intro To BOOST.Spirit
PDF
Python Data Types
Introduction To Programming with Python Lecture 2
Introduction To Programming with Python-3
Lesson 02 python keywords and identifiers
Python second ppt
Lesson 03 python statement, indentation and comments
Python Objects
Intro To BOOST.Spirit
Python Data Types

What's hot (20)

PDF
Function
PPTX
Chapter 9 python fundamentals
PDF
Python Fundamentals Class 11
PDF
PPTX
Functions in Python
PPTX
11 Unit 1 Chapter 02 Python Fundamentals
PDF
Python-01| Fundamentals
PDF
Recursion CBSE Class 12
PPTX
Python-04| Fundamental data types vs immutability
PDF
Data handling CBSE PYTHON CLASS 11
PPTX
Introduction to Python programming Language
PPTX
Functions in python slide share
PPT
Getting started with c++
PPTX
Introduction to Python Part-1
PPTX
The Awesome Python Class Part-2
PPT
Python Built-in Functions and Use cases
PPTX
Python Functions
PPTX
Fun with lambda expressions
PDF
Anton Kasyanov, Introduction to Python, Lecture2
Function
Chapter 9 python fundamentals
Python Fundamentals Class 11
Functions in Python
11 Unit 1 Chapter 02 Python Fundamentals
Python-01| Fundamentals
Recursion CBSE Class 12
Python-04| Fundamental data types vs immutability
Data handling CBSE PYTHON CLASS 11
Introduction to Python programming Language
Functions in python slide share
Getting started with c++
Introduction to Python Part-1
The Awesome Python Class Part-2
Python Built-in Functions and Use cases
Python Functions
Fun with lambda expressions
Anton Kasyanov, Introduction to Python, Lecture2
Ad

Viewers also liked (20)

PPTX
Cyberoam Firewall Presentation
PPT
Substituting HDF5 tools with Python/H5py scripts
PDF
Logic Over Language
PDF
Python and HDF5: Overview
PPTX
Introduction To Programming with Python-5
PDF
Introduction to Databases
PDF
An Introduction to Interactive Programming in Python 2013
PDF
Logic: Language and Information 1
PPTX
Introduction To Programming with Python-4
PDF
Introduction to UBI
PPT
Python 4 Arc
PPT
The Python Programming Language and HDF5: H5Py
PPTX
Clase 2 estatica
PPT
Using HDF5 and Python: The H5py module
PPTX
Python programming - Everyday(ish) Examples
PDF
Lets learn Python !
PDF
introduction to python
PPTX
Introduction to Python programming
PPTX
Introduction to Python Basics Programming
Cyberoam Firewall Presentation
Substituting HDF5 tools with Python/H5py scripts
Logic Over Language
Python and HDF5: Overview
Introduction To Programming with Python-5
Introduction to Databases
An Introduction to Interactive Programming in Python 2013
Logic: Language and Information 1
Introduction To Programming with Python-4
Introduction to UBI
Python 4 Arc
The Python Programming Language and HDF5: H5Py
Clase 2 estatica
Using HDF5 and Python: The H5py module
Python programming - Everyday(ish) Examples
Lets learn Python !
introduction to python
Introduction to Python programming
Introduction to Python Basics Programming
Ad

Similar to Introduction To Programming with Python-1 (20)

PPTX
2_3 Functions 5d.pptx2_3 Functions 5d.pptx
PPTX
An Introduction : Python
PPTX
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
PDF
GE3151 UNIT II Study material .pdf
PPTX
Lecture 08.pptx
PPTX
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
DOCX
Python interview questions and answers
PDF
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
PDF
Python interview questions and answers
DOCX
A Introduction Book of python For Beginners.docx
PDF
Python functions
PDF
Dive into Python Functions Fundamental Concepts.pdf
PPTX
Python Functions.pptx
PPTX
Python Functions.pptx
PDF
Python Interview Questions PDF By ScholarHat.pdf
PPTX
Decided to go to the 65 and the value of the number
PDF
3-Python Functions.pdf in simple.........
DOCX
Python Interview Questions For Experienced
PPTX
Python Session - 4
PPTX
Learn more about the concepts Functions of Python
2_3 Functions 5d.pptx2_3 Functions 5d.pptx
An Introduction : Python
python-fefedfasdgsgfahfdshdhunctions-190506123237.pptx
GE3151 UNIT II Study material .pdf
Lecture 08.pptx
INTRODUCTION TO PYTHON PROGRMMING AND FUNCTIONS
Python interview questions and answers
All chapters C++ - Copy.pdfyttttttttttttttttttttttttttttt
Python interview questions and answers
A Introduction Book of python For Beginners.docx
Python functions
Dive into Python Functions Fundamental Concepts.pdf
Python Functions.pptx
Python Functions.pptx
Python Interview Questions PDF By ScholarHat.pdf
Decided to go to the 65 and the value of the number
3-Python Functions.pdf in simple.........
Python Interview Questions For Experienced
Python Session - 4
Learn more about the concepts Functions of Python

More from Syed Farjad Zia Zaidi (20)

PPTX
Vision & sight
PDF
Introduction to Computing with Java
PDF
Web Application Architectures
PDF
Foundations of Virtual Instruction
PDF
Programming for Everybody (Python)
PDF
Learn to Program: The Fundamentals
PDF
Introduction to Systematic Program Design - Part 1
PDF
Emerging Trends & Technologies in the Virtual K-12 Classroom
PDF
An Introduction to Interactive Programming in Python 2014
PDF
Internet History, Technology, and Security
PDF
Human-Computer Interaction
PDF
Beginning Game Programming with C#
PDF
Programming Mobile Applications for Android Handheld Systems 2014
PDF
Computer Science 101
DOCX
Software Requirement Specification - Software Pack Solution 14
DOC
Project Proposal - Software Pack Solution 14
PDF
Database Diagram Tutorial-SQL Server 2012
DOCX
MindMuscle Xtreme
PDF
How to connect database file to a 3-Tier Architecture Application and obtain ...
PDF
Vision & sight
Introduction to Computing with Java
Web Application Architectures
Foundations of Virtual Instruction
Programming for Everybody (Python)
Learn to Program: The Fundamentals
Introduction to Systematic Program Design - Part 1
Emerging Trends & Technologies in the Virtual K-12 Classroom
An Introduction to Interactive Programming in Python 2014
Internet History, Technology, and Security
Human-Computer Interaction
Beginning Game Programming with C#
Programming Mobile Applications for Android Handheld Systems 2014
Computer Science 101
Software Requirement Specification - Software Pack Solution 14
Project Proposal - Software Pack Solution 14
Database Diagram Tutorial-SQL Server 2012
MindMuscle Xtreme
How to connect database file to a 3-Tier Architecture Application and obtain ...

Recently uploaded (20)

PDF
How to Choose the Right IT Partner for Your Business in Malaysia
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PPTX
CHAPTER 2 - PM Management and IT Context
PDF
Understanding Forklifts - TECH EHS Solution
PDF
Nekopoi APK 2025 free lastest update
PDF
System and Network Administration Chapter 2
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
medical staffing services at VALiNTRY
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PPTX
L1 - Introduction to python Backend.pptx
PDF
Design an Analysis of Algorithms II-SECS-1021-03
PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PPTX
Transform Your Business with a Software ERP System
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PDF
AI in Product Development-omnex systems
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PPTX
history of c programming in notes for students .pptx
How to Choose the Right IT Partner for Your Business in Malaysia
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
How to Migrate SBCGlobal Email to Yahoo Easily
CHAPTER 2 - PM Management and IT Context
Understanding Forklifts - TECH EHS Solution
Nekopoi APK 2025 free lastest update
System and Network Administration Chapter 2
Adobe Illustrator 28.6 Crack My Vision of Vector Design
medical staffing services at VALiNTRY
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
L1 - Introduction to python Backend.pptx
Design an Analysis of Algorithms II-SECS-1021-03
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
Transform Your Business with a Software ERP System
VVF-Customer-Presentation2025-Ver1.9.pptx
AI in Product Development-omnex systems
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
history of c programming in notes for students .pptx

Introduction To Programming with Python-1

  • 1. Introduction to Programming with Python – Class 1 SYED FARJAD ZIA ZAIDI
  • 2. Class Objectives Class Objective Review variables, statements, expressions, functions, algorithms and technical terms. Understanding Flow Control. Write a simple program that performs addition, subtraction, multiplication and division using Functions.
  • 3. Class Material •Chapter 1, 2, 3 - Python for Informatics: Exploring Information Reading Assignment •Rock, Paper, Scissors
  • 4. Variables  Definition: A named piece of memory that can store a value.  Statement: A statement written in a programming language stores a value in a variable. Example: X = 5 Y = 1  Expression: A variable that has a value can be used in an expression. Example: X = X + 4 Y = X + 1
  • 5. Rules for defining a Variable:  Names must start with a letter or _.  Names must contain only letters, digits, and _.
  • 7. Functions  Definition: A function is a block of organized, reusable code that is used to perform some action.  Defining a function: You can define a function in Python using the Keyword ‘def’.  General Form of Function: def function_name(parameters): body Example: def MyFirstFunction(): print “This is my first function in Python Programming Language”
  • 8. Defining Functions You can define functions to provide the required functionality. Here are simple rules to define a function in Python.  Function blocks begin with the keyword ‘def’ followed by the function name and parentheses ‘( )’ . Example: def MyFirstFunction():  Any input parameters or arguments should be placed within these parentheses. You can also define parameters inside these parentheses. Example: def MySecondFunction(passedInput):
  • 9. Defining Functions  The first statement of a function can be an optional statement - the documentation string of the function or docstring. Example: def MyFirstFunction(): “””This is the 'docstring' which defines the function for other programmers to understand easily”””  The code block within every function starts with a colon (:) and is indented.
  • 10. Defining Functions  The statement return [expression] exits a function, optionally passing back an expression to the caller. A return statement with no arguments is the same as return None.  General Form of Return Statement: return [expression] Example: def MyFunction(): “”“A function that returns a message””” return “This is a function that returns a message”
  • 11. Calling a function  Function calls are expressions and the result can be stored in a variable. The general form of a function call: function_name(arguments) Example: MyFirstFunction() MySecondFunction(“Input Parameter”)
  • 13. Source Code vs Object Code Source Code Object Code Source Code is a text file version of a computer program or software that contains instructions that the computer follows to do something Object code, or sometimes an object module, is what a computer compiler produces Source code is written in a programming language which a human can read and change In a general sense object code is a sequence of statements or instructions in a computer language, usually a machine code language (i.e., 1's and 0's) Most source code is compiled when it is finished Object code is the resulting code after compiling source code
  • 14. Compiler  A compiler is a computer program (or set of programs) that transforms source code written in a programming language (the source language) into another computer language (the target language, often having a binary form known as object code). The most common reason for wanting to transform source code is to create an executable program.
  • 16. Flow Control of the Program  Selection (If/Else)  Repetition (Loops)
  • 17. Conditional Execution  In order to write useful programs, we almost always need to check some conditions and change the program accordingly. Conditional Statements gives us this ability. The simplest form is if statement.  General Form: if [expression1]: body1 elif [expression2]: body2 else: bodyN
  • 18. Python Comparison Operators Operator Description == Checks if the value of two operands are equal or not, if yes then condition becomes true. != Checks if the value of two operands are equal or not, if values are not equal then condition becomes true. < Checks if the value of left operand is less than the value of right operand, if yes then condition becomes true. > Checks if the value of left operand is greater than the value of right operand, if yes then condition becomes true. >= Checks if the value of left operand is greater than or equal to the value of right operand, if yes then condition becomes true. <= Checks if the value of left operand is less than or equal to the value of right operand, if yes then condition becomes true.
  • 19. Python Logical Operators Operator Description and Called Logical AND operator. If both the operands are true then then condition becomes true. or Called Logical OR Operator. If any of the two operands are non zero then then condition becomes true. not Called Logical NOT Operator. Use to reverses the logical state of its operand. If a condition is true then Logical NOT operator will make false.
  • 21. Simple Calculator  Definition: A calculator is a machine which allows people to do math operations more easily. For example, most calculators will add, subtract, multiply, and divide.  Instructions for writing the Program:  There should be 4 functions in your program:  Add(number1, number2)  Subtract(number1, number2)  Multiply(number1, number2)  Divide(number1, number2)  The template for the program can be accessed here: http://www.codeskulptor.org/#user37_44o34rWsnC_18.py
  • 23. Rock Paper Scissors – 1st Mini- Project Rock-paper-scissors is a hand game that is played by two people. The players count to three in unison and simultaneously "throw” one of three hand signals that correspond to rock, paper or scissors. The winner is determined by the rules:  Rock smashes scissors  Scissors cuts paper  Paper covers rock
  • 24. Instruction  In our first mini-project, we will build a Python function rps(name) that takes as input the string name, which is one of "rock", "paper", "scissors“. The function then simulates playing a round of rock-paper-scissors by calling a helper function gen_random_num() that generate own random choice from these alternatives and then determining the winner using simple if / else statements.  The mini-project template is here: http://www.codeskulptor.org/#user37_HJPdXx35jy_0.py
  • 25. Example runs Player chooses rock Computer chooses scissors Player wins! Player chooses paper Computer chooses scissors Computer wins! Player chooses scissors Computer chooses paper Player wins!