Me 5
Me 5
Me 5
AND PROGRAMMING
Meeting 4
Dr. Ahmed Ezzat Labib
READING INPUT FROM THE KEYBOARD
• the input function in an assignment statement that follows this general format:
variable = input(prompt)
• prompt is a string that is displayed on the screen.
• The string’s purpose is to instruct the user to enter a value
• variable is the name of a variable that references the data that was entered on the
keyboard.
EXAMPLE 1
>>> print(name)
Holly
>>>
EXAMPLE 2
Function Description
int(item) You pass an argument to the int( ) function and it
returns the argument’s value converted to an int.
Equivelant To
Expression Value
(5 + 2) * 4 28
10 / (5 − 3) 5
8 + 12 * 6 − 2 78
(6 − 3) * (2 + 7) − 1 9
2**3**2 512
17 % 3 2
5//2 2
5/2 2.5
CONVERTING MATH FORMULAS TO PROGRAMMING
STATEMENTS
Algebraic Expression Programming Expression
𝟔𝐁 6*B
(𝟑)(𝟏𝟐) 3 * 12
𝟒𝐱𝐲 4*x*y
𝒂+𝒃 (a+b)/c
𝒙=
𝒄
𝒙 3*x/2
𝒚=𝟑
𝟐
𝒛 = 𝟑𝒃𝒄 + 𝟒 z=3*b*c+4
𝒙+𝟐 a=(x+2)/(b–1)
𝒂=
𝒃−𝟏
BREAKING LONG STATEMENTS INTO
MULTIPLE LINES
units_sold = 3
sales_amount = 20
print('We sold', units_sold, \
'for a total of', sales_amount)
OneTwoThree
SUPPRESSING THE PRINT FUNCTION’S
ENDING NEWLINE
>>> print('One', 'Two', 'Three', sep='')
OneTwoThree
SUPPRESSING THE PRINT FUNCTION’S
ENDING NEWLINE "" ﺧﺎﺭﺝ
One*Two*Three
SUPPRESSING THE PRINT FUNCTION’S
ENDING NEWLINE
>>> print('One', 'Two', 'Three', sep='---')
One---Two---Three
ESCAPE CHARACTERS
print('One\nTwo\nThree')
One
Two
Three
ESCAPE CHARACTERS ""ﺩﺍﺧﻞ ﺍﻝ
print('Mon\tTues\tWed')
print('Thur\tFri\tSat')