CC 102:
FUNDAME
NTALS OF
PROGRAM
MING
TODAY’S LECTURE TOPICS:
• Basic Python Arithmetic
Operations
• input() function or Python
User Inputs
CC 102: Fundamentals of Programm
BASIC
ARITHMETIC
OPERATORS IN
PYTHONCC 102: Fundamentals of Programm
BASIC ARITHMETIC OPERATORS
Operation Symbol
Addition +
Subtraction -
Multiplication *
Division /
CC 102: Fundamentals of Programm
ADDITION.
CODE EDITOR: OUTPUT WINDOW:
20
x = 15
y = 5
z = x + y
print(z)
CC 102: Fundamentals of Programm
SUBTRACTION
CODE EDITOR: OUTPUT WINDOW:
10
x = 15
y = 5
z = x - y
print(z)
CC 102: Fundamentals of Programm
MULTIPLICATION
CODE EDITOR: OUTPUT WINDOW:
75
x = 15
y = 5
z = x * y
print(z)
CC 102: Fundamentals of Programm
DIVISION
CODE EDITOR: OUTPUT WINDOW:
3
x = 15
y = 5
z = x / y
print(z)
CC 102: Fundamentals of Programm
PYTHON USER
input()
INPUTS
CC 102: Fundamentals of Programm
Python User Inputs: input() function
Para asa mana?
CC 102: Fundamentals of Programm
Python User Inputs: input() function
Para asa mana?
name = “Jose Rizal”
Most of the time
pangayuon pa nato ni nga
value from users.
CC 102: Fundamentals of Programm
Python User Inputs: input() function
Para asa mana?
input()
CC 102: Fundamentals of Programm
Python User Inputs: input() function
Para asa mana?
Ako na bahala
input()
mangayo sa
data sa user.
CC 102: Fundamentals of Programm
Python User Inputs
CODE EDITOR:
input()
OUTPUT WINDOW:
Juan Dela Cruz
CC 102: Fundamentals of Programm
Python User Inputs
CODE EDITOR:
print(“Enter your name: ”)
input()
OUTPUT WINDOW:
Enter your name:
Juan Dela Cruz
CC 102: Fundamentals of Programm
Python User Inputs
CODE EDITOR:
print(“Enter your name: ”)
name = input()
print(“Hello, ” + name + “!”)
OUTPUT WINDOW:
Enter your name:
Juan Dela Cruz
Hello, Juan Dela Cruz!
CC 102: Fundamentals of Programm
Python User Inputs
CODE EDITOR:
name = input(“Enter your name: ”)
print(“Hello, ” + name + “!”)
OUTPUT WINDOW:
Enter your name: Juan Dela Cruz
Hello, Juan Dela Cruz!
CC 102: Fundamentals of Programm
LECTURE EXERCISE:
Create a program that has the following
specification(s):
• Has a variable called “user_name” with the value that is based
on user input.
• The program should print the value of the user_name variable
with the greetings as specified below.
The program should have
the output:
Welcome to my simple program!
Please enter your name:
Thank you for your input, Juan Dela Cruz!
This data is based on user input.
CC 102: Fundamentals of Programm
DAY 2: PYTHON CHEAT SHEET
Python
1 can perform arithmetic operations.
Operation Symbol CODE EDITOR: OUTPUT
WINDOW:
x = 15 20
Addition + y = 5
10
75
{
Subtraction - sum = x + y
diff = x - y
3
Multiplication * prod = x * y
quo = x / y
Division / print(sum)
print(diff)
print(prod)
sum = 15 + 5 = 20
print(quo)
diff = 15 - 5 = 10
prod = 15 * 5 = 75
sum = 15 / 5 = 3
CC 102: Fundamentals of Programm
DAY 2: PYTHON CHEAT SHEET
Python
2 accepts user input using the input() function.
a input()
Let’s a user input on output window when program is run.
b variable_name = input() Example:
• If user inputs the value: “Sample va
• Let’s a user input on output
• Then: variable_name = “Sample va
window when program is run.
• Set variable_name value based
on user input.
c variable_name = input(“Enter a value: ”)
• Let’s a user input on Example:
• Output Window displays: “Enter a value: “
output window after the
• If user inputs the value: “Another Sample value”
“Enter a value: ” phrase
• Then: variable_name = “Another Sample value”
when program is run.
• Set variable_name value
based on user input. CC 102: Fundamentals of Programm