JAVA = String name = “FCPC”; - Explicit Casting – normally declaring the data type
Python = name = “FCPC” – Implicit Casting – data type is automatically decided
# Key Concepts in Programming
# 1. Variables
# 2. Data Types & Casting
# 3. Input/Output & String Concatenation
# 4. Operators
# 4.1 - Arithmetic (Mathematical)
# 4.2 - Relational (Comparison)
# 4.3 - Logical (Conditional)
# Variable - is container or holder of information
# Declaring Variable
# Syntax:
# variable name = VALUE/DATA
section = "BSIT 1B"
age = 18
pi = 3.14159
# Rules in naming variables:
# 1. must start with letter or underscore(_)
# 2. must not contain special characters
# 3. must not contain white space (tab, enter, space)
# 4. case-sensitive: AGE is not the same as age
# 5. avoid using keywords.
# Data Type - is the type stored in a variable.
# type() - returns the data
# 1. Integers (int) - numbers, + or -, with no decimal point.
age = 18
year = 2025
#print(type(year))
# 2. Floats (float) - numbers, + or -, WITH decimal point. 0 to 9 only.
pi = 3.14159
absolute_zero = -273.15
#print(type(absolute_zero))
# 3. String (str) - collection of characters enclosed by "" or ''
greeting = "Hello World!"
#print(type(greeting))
# 4. Booleans (bool) - True or False
honest = True
dishonest = False
#print(type(honest))
# Types Casting
# 1. Implicit Casting - python's default, data type is decided automatically.
section = "BSIT 1B"
age = 18
# 2. Explicit Casting - data type is manually changed or declared.
# a. int() - changes the data type to an integer.
num1 = int("100")
num2 = int(3.9) # 3.14 (float) -> 3 (int, removes the decimal places)
num3 = int(True) # True(bool) -> 1 (int)
#print(num1 / 5) # 20.0
# b. float() - changes the data type to an float. 0 - 9 and decimal point.
num1 = float(100.00)
num2 = float(100) # 100 (int) -> 100.0 (float)
num3 = float(False) # False (bool) -> 0.0 (float)
#print(num1 * 12) # 1200.00
# c. str() - changes the data type to a string. Mostly used for casting concatination.
# num1 = str(100.0) # 100.0 (float) -> "100.0" (str)
num1 = 100.0
num2 = str(True) # True (bool) -> "True" (str)
#print("Your baon is " + str(num1))
# num2 = str(18) # 18 (int) -> "18" (str)
num2 = 18
#print("Your age is " + str(num2))
# d. boo() - changes the data type to a boolean.
# String -> Boolean: True when string is not empty.
#print(bool("FCPC")) # True because string is not empty.
#print(bool("")) # False because string is empty.
# Integer to Boolean: True when integer is not 0.
#print(bool(12568))
#print(bool(-123))
#print(bool(0))
# Float -> Boolean: True when float is not 0.0
#print(bool(12.568))
#print(bool(-12.3))
#print(bool(0.0))
# Python Output - display something to terminal
# print()
#print("BSIT 1B")
# Python Input - asks user for an information or an input.
# input(INSTRUCTION_QUESTION_PROMPT)
# Syntax:
# variable_name = input(INSTRUCTION_QUESTION_PROMPT)
#num1 = input("Enter num1: ")
#result = float(num1) * 5.25
#print("The result is " + str(result))
# Weight Converter:
weight = input("Enter your weight in kilograms: ")
pounds = float(weight) * 2.20
print(weight + " kilograms is " + str(pounds) + " pounds.")
# 50 kilograms is 110.0 pounds.
# Python Operators
# - are symbols or combination of symbols that perform in a specific operations.
# 1. Arithmetic Operators (Mathematical) - perform math operations.
# a. Addition +
#print(50 + 50 + 25) # 25
# b. Subtraction -
#print(50 - 50 - 25) # -25
# c. Multiplication *
#print(50 * 50 * 2) # 5000
# e. Exponentiation **
#print(2 ** 4) # 2x2x2x2 = 16
#print(3 ** 3) # 3x3x3 = 27
# d. Division / - cannot divide by 0
#print(154 / 6) # 25.66
# print(154 / 0) # Error
# f. Floor Division // - getting the quotient
#print(154 // 6) # 25
# g. Modulus % - getting the remainder
#print(154 % 6) # 4
# 2. Relational (Comparison) Operations
# - compares operands based on Operators
# NOTE: Always results to True or False
baon = 100
pamasahe = 50
napulot = 100
# a. greater than >
#print(baon > pamasahe) # 100 > 50: True
#print((baon - pamasahe) > napulot) # 100-50 > 100: False
#print((2 + 3) * 5 > (21 - 8) * 2) # 25 > 26: False
# b. greater than or equal >=
q1 = 80
q2 = 70
q3 = 95
ave = (q1 + q2 + q3) / 3
no_below_50 = q1 > 50 and q2 > 50 and q3 > 50
#print(ave) # 81.66
#print(ave >= 75) # 81.66 > 75: True
# c. less than <
baon = 100
pamasahe = 50
napulot = 100
# print(pamasahe < baon) # is pamasahe (50) less than baon (100)? True
# d. less than or equal <=
# print(baon <= napulot) # is baon (100) less than or equal napulot (100)? True
# e. is equal to ==
#print(int("100") == 100)
#print(100 == 100)
# f. is not equal to !=
#print("100" != 100) # TRUE
#print(99 != 100) # TRUE
# Logical (Conditional) Operator
# - operands has to meet specific conditions to be True or False.
# not - inverts boolean value
#print("not True = " + str(not True)) # False
#print("not False = " + str(not False)) # True
# and - all operands to be True for the expression to be True. Dapat lahat True. Otherwise, False.
# q1 = 80
# q2 = 70
# q3 = 95
# ave = (q1 + q2 + q3) / 3
# no_below_50 = q1 > 50 and q2 > 50 and q3 > 50 and ave > 75
# print(no_below_50)
absent = 2
grade = 85
masipag = absent < 3
tahimik = True
matalino = grade > 75
good_student = masipag and tahimik and matalino
print("Are you a good student? " + str(good_student))
# or - at least one (1) of the operands has to be True for the expression to be True.
# ["pag may True, True."]
age = 18
long = age < 18 or age == 18 # TRUE
short = age <= 18 # TRUE
print("Long version: " + str(long))
print("Short version: " + str(short))
# Celcius to Fahrenheit
celsius = input("Enter temp in celcius: ")
fahrenheit = float(celsius) * 9/5 +32
print(celsius + " celsius is " + str(fahrenheit) + " fahrenheit")
too_hot = float(celsius) > 25
print("is " + celsius + " celsius too hot? " + str(too_hot))
# is 50 Celsius too hot? True