0% found this document useful (0 votes)
14 views

Basic Fundamentals

Uploaded by

Catherine Benban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Basic Fundamentals

Uploaded by

Catherine Benban
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Programming Essential Course

What is Python?
▪ Python is an interpreted, object-oriented, high-level programming language.
▪ It was created by Guido van Rossum, released in 1991.

Key Advantages of Learning Python:


▪ Python is Interpreted
▪ Python is Beginner’s Language
▪ Python is Object-Oriented

It is used for:
▪ Web Development (server-side),
▪ Software Development
▪ Data Science and Data Visualization
▪ Machine Learning
▪ Script for Vulnerability Testing
Printing
Python uses print() function to display text or value.

Examples:
▪ print(“Hello world”)
▪ print(‘Hello world’)
▪ print(30)
▪ print(1.5)
Escape Character
▪ To insert characters that are illegal in a string
▪ An escape character is a backslash \ followed by
the character you want to insert.

Examples:
▪ \’ - Single Quote
▪ \” - Double Quote
▪ \\ - Backslash
▪ \n - New Line
▪ \t - Tab
Indentation
Python uses indentation to indicate code block.

if grade >= 75:


print(“Passed”)
else:
print(“Failed”)
Variables
● Variables are containers for storing data
values.
● A variable
is created the moment you first
assign a value to it.
name = “John Doe”
age = 30
Data Types
Type of data stored in a variable
● String (“Hello World”, “U$niverse*”)
● Integer (1,5,-3,-2)
● Float (1.5,2.6, 1.67, 500.45)
● Double (23232.3434, 2345.567678)
● Boolean (True, False)
● Byte (8 bits )
Casting
▪ Converting one data type into another.

▪ If you want to specify the data type of a variable

x = str(3)
y = int(3)
z = float(3)
Basic types of placeholders

▪ %c - Represents a single letter or symbol


▪ %s - Represents a group of characters
▪ %d %i - Represent integer
▪ %f - Represents a number with decimal
points
String Placeholders
Container for Strings and Variable
▪ {} format
▪%
▪ f {}
{} format Placeholder
name = "John"
food = "Burger"
game = "Mobile Legend"

text1 = "My name is {} I love {} and playing {}"


info1 = text1.format(name, food, game)
print(info1)

text2 = "My name is {2} I love {1} and playing {0}"


info2 = text2.format(name, food, game)
print(info2)

text3 = "My name is {newname} I love {newfood} and playing {newgame}"


info3 = text3.format(newname="Chris", newfood="Fries",
newgame="Chess")
print(info3)
% Placeholder

name = “John”
age = 30
print(“My name is %s, I am %d years old.” %(name, age) )

item = "milk"
price = 35.526

text = "The product %s costs %.2f" %(item, price)


print(text)
f {} Placeholder

item = "milk"
price = 35.50

print( f"The product {item} costs {price*100} pesos” )


input() function

Accepting user’s input


Example:
name = str( input(“Enter your name: ”) )
age = int(input(“Enter your age: ”) )
print(f “My name is: {name}”)
print(f “I am {age} years old”)
Create a Simple Weekly Payroll.
The program should accept the following inputs:
- Number of hours rendered
- Rate per hour
- GSIS Premium Contribution
- PhilHealth Contribution
- Housing Loan
- Tax percentage rate (example input: 25, the program will treat it as 0.25).
The program should compute the weekly gross salary, total deductions and
weekly net salary. The program should display the weekly gross salary,
weekly net salary and total deductions on the screen.
Sample Run of the Program

Enter number of hours rendered: 40 Gross Salary: 20000


Enter rate per hour: 500 Total deductions: 7100.0
GSIS Premium: 800 Net Salary: 12900.0
PhilHealth: 300
Housing Loan: 1000
Tax rate: 25
Number Formatting Functions

Number data types store numeric values. They are immutable


data types; it means that changing the value of a number data
type will result in a newly allocated object.

Number formatting functions


● round()
● ceil()
● floor()
● pow()
String Formatting Functions

● upper() - Converts a string into upper case


● lower() - Converts a string into lower case
● capitalize() - Converts the first character to uppercase
● title() - Converts the first character of each word to uppercase
● split() - Splits the string at the specified separator, and returns a list
● replace()-Returns a string where a specified value is replaced with a specified value
● len() – counts the number of characters in a string
● count() – (occurences) Returns the number of times the value appears in the string

You might also like