PYTHON
WEEK 1
FLOW CHARTS
• A flowchart is a type of diagram that represents a workflow or process
EXAMPLE
CHECK THE ERROR !!!
• The error in this flow chart is: (prints)
PROGRAMMING LANGUAGE
HIGH LEVEL VS LOW LEVEL
LANGUAGES
A COMPILER
COMPILER VS INTERPRETER
COMPILATION PROCESS
PROGRAMS TO DOWNLOAD
1- python Interpreter – python 3 (any version)
Link : [Link]
PROGRAMS TO DOWNLOAD
1- IDE: Pycharm Community Edition. Link :
[Link]
tion=windows
PYTHON
WEEK 2
FIRST PROGRAM
• print(“Hello World”);
• print() => will display something on the screen
COMMENTS IN PYTHON
• A hash sign (#) that is not inside a string literal begins a
comment. All characters after the # and up to the end of the
physical line are part of the comment and the Python
interpreter ignores them.
# First comment
Print("Hello, Python!“) # second comment
• This produces the following result −
Hello, Python!
COMMENTS IN PYTHON
You can type a comment on the same line after a statement or expression −
name = “Michel" # This is again comment
You can comment multiple lines as follows −
# This is a comment.
# This is a comment, too.
# I said that already.
Or use:
MULTIPLE STATEMENTS ON A SINGLE
LINE
• The semicolon ( ; ) allows multiple statements on the single
line given that neither statement starts a new code block. Here
is a sample snip using the semicolon −
• print ("hello“) ; print("there“); print( "!“)
VARIABLES
• Variables reserved memory locations to store values (containers
for storing data values)
• Call up the value through variable name
• no command for declaring a variable.
• Ex:
height = 1.78
print(height) #Output: 1.78
VARIABLE NAMES RULES
• 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)
VARIABLES AND TYPES
• Numbers:
• Python supports two types of numbers –
1- integers and 2- floats numbers.
• To define an integer, use the following syntax:
• To define a floating point number, you may use one of the
following notations:
VARIABLES AND TYPES
• 3- Strings
• Strings are defined either with a single quote or a double quotes.
String is collection of characters
What is the difference? Check the double and single quotes
• 4- Booleans:
NOTES
• Assignments can be done on more than one variable "simultaneously"
on the same line like this
a, b = 3, 4
a=b=c=1
• Mixing operators between numbers and strings is not supported:
# This will not work!
print (5 + “hello”)
PYTHON
WEEK 3
CONCATENATION
# Simple operators can be executed on strings:
# variable (message) will carry the result of concatenating 2
strings
So, To concatenate 2 strings use + operator
DEMO 1
• Demo 1 Scan data from user
Program steps:
1- Scan user data
2- display this data
# step 1 (how to insert data to the program) => next slide
# Step 2
Print(“hello, my name is “, name”)
DEMO 1 => WAITING FOR THE USER
• Input("enter your name")
# this statement is used to allow the user to enter data
to the program.
“enter your name” message will display in the
program, and will wait for the user to take action
CASTING
• Anything will be entered using input() will be considered String
• x=input(“”) # x is a variable and its value is string type
• Using input(): What if the user entered a number like 5??
• Assign 5 to x, it will be string not number.
Solution: CASTING
• Type() => use type() to know the type of the variable