Intro To Comp and Prop - DAY 4
Intro To Comp and Prop - DAY 4
SESSION 4
1
CONTENT
1. Data & Error Types, Debugging and String Formatting
2.
3.
• There are three basic types of data that we will be working with during
the first half of the term
• Strings (character-based data)
• Numbers
• Logical Values (True / False)
pythontutor.com
Introduction to Computer and Programming 24
Advanced Math Operations
Division Operations:
• Python contains two different division operators
• The “/” operator is used to calculate the floating-point result
of a division operation
• The “//” operator is used to calculate the integer result of a
division operation (essentially throwing away the remainder). This operation
will always round down.
• Most times you will use the floating-point division operator (“/”)
• Separating:
print(‘one’, ‘two’, sep=‘*’) # output: one*two
X Y X*Y
5 4 20
Product Price
product1 price1
product2 price2
product3 price3
# Fa La La La La La La La La
• format() returns a string which can be treated like any other string (i.e.
you can print it out immediately, store its value in a variable, etc)
x = “Hello, World!”
y = format(x, ‘>20s’)
print(x)
>> Hello, World!
print(y)
>> Hello, World!
a = 20000
print(format(a, ',d’)) # 20,000
print(format(a, ’>20,d’)) # 20,000
Product Price
product1 price1
product2 price2
product3 price3