0% found this document useful (0 votes)
1 views13 pages

Python Script Reviewer

The document covers fundamental concepts in Python programming, including data types, input/output functions, control flow, and practical applications such as electricity billing and payroll calculations. It provides examples of basic arithmetic operations, decision-making structures like if-else statements, and advanced features like recursion and pattern matching. Additionally, it emphasizes the importance of type casting and variable management in programming logic.

Uploaded by

g7wsdrb5b2
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)
1 views13 pages

Python Script Reviewer

The document covers fundamental concepts in Python programming, including data types, input/output functions, control flow, and practical applications such as electricity billing and payroll calculations. It provides examples of basic arithmetic operations, decision-making structures like if-else statements, and advanced features like recursion and pattern matching. Additionally, it emphasizes the importance of type casting and variable management in programming logic.

Uploaded by

g7wsdrb5b2
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

Part 1: Basic Input/Output and Data Types

In Python, handling different types of data is essential for performing calculations and displaying
information correctly.

Core Concepts
• print(): Displays information to the console.
• input(): Captures user input as a string by default.
• Type Casting: Converting one data type to another (e.g., int(input()) converts the text input into an
integer).
• type(): A built-in function used to identify the data type of a variable.

Data Type Reference Table


Based on your examples, here are the common types you will encounter:

Type Name Example from your Code

str String (Text) "Hello World", "Manager"

int Integer (Whole Number) 10, 42

float Floating Point (Decimal) 11.22, 500.0

list List (Ordered collection) ["Geeks", "for", "Geeks"]

tuple Tuple (Unchangeable list) ("Geeks", "for", "Geeks")

dict Dictionary (Key-Value) {"Geeks": 1, "for": 2}


Part 2: Control Flow (Decision Making)
Control flow allows your program to execute different code blocks based on specific conditions.

1. If-Else Statements
These are used to check conditions sequentially.
• if: The initial condition.
• elif (Else If): Checked only if the previous if was false.
• else: The "catch-all" if no previous conditions were met.
Reviewer Tip: In your "[Link]" script, you use a long chain of elif statements to determine a
Grade Point based on a calculated Final_Grade. If the first if is true, Python skips all the elif and
else blocks below it.

2. Logical Operators
Used to combine multiple conditions:
• and: True if both conditions are true.
• or: True if at least one condition is true.
• Modulo (%): Used to find remainders (e.g., number % 2 == 0 checks if a number is even).

3. Structural Pattern Matching (match-case)


A cleaner way to handle multiple specific values for a single variable, as seen in your operator and payroll
scripts.
• case _:: Acts as the "default" case if no other match is found.
• Pipe (|): Allows matching multiple values in one case (e.g., case 2|3:).

Part 3: Practical Program Logic


Your scripts include "Real-World" applications of programming logic.

1. Electricity Billing Logic


In your electricity bill scripts, you use conditional ranges to determine the rate per kWh:
• Tiered Rates: Assigns a price c based on consumption b.
• Lifeline Discount: A specific if statement checks if consumption is $\le 50$ to apply a 20%
discount.

2. Payroll and Deductions


Your payslip programs demonstrate how to calculate overtime and net pay:
• Overtime: if c > 40: calculates pay for hours exceeding the standard 40-hour work week.
• Deductions: Substracting fixed costs (SSS, PhilHealth) and calculated taxes from the Gross Pay.

3. Recursion for Repetition


In your "Loop Code" files, you use a technique where the main() function calls itself:
• If the user enters "yes" for the "Repeat" prompt, the program restarts by calling main() again.
• Important: This is a basic way to loop, but for larger programs, "while" or "for" loops are usually
preferred to prevent memory issues.
I. Basic Input and Mathematical Operations
1. [Link]
Python

print("Quiz 1")
print("by James Amiel S. Peneyra")
print("")
x = int(input("Enter the first number: "))
y = int(input("Enter the second number: "))

Sum = x + y
Difference = x - y
Product = x * y
Quotient = float(x / y)

print("")
print("The results are the following:")
print("Sum:",Sum)
print("Difference:",Difference)
print("Product:",Product)
print("Quotient:",Quotient)

● Functional Description: This script demonstrates Arithmetic Operators and Input Handling. It
prompts the user for two integers, performs basic math (addition, subtraction, multiplication, division),
and outputs the results. Note that it explicitly casts the quotient to a float to ensure decimal precision.

II. Decision Making: If...Else Statements


2. if..else Statements1 Meet#[Link]
Python

age = int(input("Enter the age: "))


if age >=18:
print("Eligible to vote.")
else:
print("Not eligible to vote.")

age = int(input("Enter the age: "))


if age >= 18: print("Eligible to vote.")

● Functional Description: This script illustrates Relational Operators (>=) and the basic structure of a
Conditional Statement. It also shows a "Short Hand If," where the code to execute is on the same line
as the condition.
3. if..else Statements3 Meet#[Link]
Python

x = int(input("Enter the grade: "))


if x<=60 and x>40:
print("Your grade is C")
if x<=80 and x>60:
print("Your grade is B")
if x<=100 and x>80:
print("Your grade is A")
if x<40 and x>0 or x>100:
print("Abnormal ka")
if x==0:
print("BOBO KA")

● Functional Description: This script uses Logical Operators (and, or) to define specific numeric
ranges. Unlike an elif chain, these are independent if statements, meaning Python checks every single
one of them regardless of whether a previous condition was met.

4. if..else Statements4 Meet#[Link]


Python

age = int(input("Enter your age:"))


if age <= 12:
print("You are a child.")
elif age <= 19:
print("You are a teenager.")
elif age <= 35:
print("You are a young adult.")
elif age <=60:
print("You are an adult.")
else:
print("You are paking old.")

● Functional Description: This script demonstrates an elif chain. Unlike independent if statements,
once a condition is found to be true, the rest of the chain is skipped. This is more efficient for
categorization tasks like age grouping.
III. Pattern Matching: Match-Case
5. if..else Statements6 Meet#[Link]
Python

operator=input("Enter an Operator: ")


x = int(input("Enter a Number as x: "))
y = int(input("Enter a Number as y: "))

match operator:
case'+':
result = x+y
case'-':
result = x-y
case'*':
result = x*y
case'/':
result = x/y
case _:
result = "Unsupported Operator"

print(result)

● Functional Description: This script uses Structural Pattern Matching (match-case) to simulate a
calculator. It compares the operator variable against specific symbols. The underscore _ serves as a
wildcard to handle any input that doesn't match the specified operator.

IV. Complex Logic and Grading Systems


6. [Link]
Python

# (Input section omitted for brevity)


w = float(((c+f+j)/300)*0.21)
x = float(((a+b+e+h+i)/500)*0.20)
y = float(((d+g+l)/300)*0.45)
z = float((k/100)*0.14)

Final_Grade = (w+x+y+z)*100
print("Final Grade: ",Final_Grade,"%")

if 95.52<=Final_Grade<=100:
print("Equivalent Grade Point: 1.00")
# (Subsequent elif statements omitted)
● Functional Description: This script demonstrates Weighted Grade Calculation. It aggregates
multiple scores, calculates their percentage relative to a total, and applies a weight (e.g., 21%, 20%). It
then uses a detailed elif chain to translate that final percentage into a numerical Grade Point.

V. Advanced Functional Logic and Recursion


7. Meet Activity#4 Loop Code [Link]
Python

def main ():


# (Input and match-case logic)
Repeat = input("Would you like to enter another employee? (yes/no):")
if Repeat == "yes":
main()
else:
print("Program has ended")
exit()
main()

● Functional Description: This script is a full-scale Payroll System that incorporates Recursion. By
calling main() inside itself, the program creates a loop that allows the user to process multiple
employees without restarting the script manually. It also calculates overtime pay and multiple tax
deductions.

8. Meet Activity#4 Loop Code [Link] (Electricity Bill)


Python

def main ():


# (Input and conditional rate logic)
if b <= 50:
e = d * 0.2 # 20% Lifeline Discount
else:
e=0
f = d - e + 15 # Includes Meter Charge
# (Output and recursion logic)

● Functional Description: This script calculates an Electricity Bill using Nested Conditions. It first
determines the rate per kWh based on consumption, then checks if the user qualifies for a "Lifeline
Discount" (consumption $\le 50$). It also demonstrates the use of a fixed "Meter Charge" constant in
the final calculation.
VI. Understanding Variable Types and Memory
9. [Link]
Python

a = "Hello World"
b = 10
c = 11.22
d = ("Geeks","for","Geeks")
e = ["Geeks","for","Geeks"]
f = {"Geeks":1,"for":2,"Geeks":3}
print(type(a))
print(type(b))
print(type(c))
print(type(d))
print(type(e))
print(type(f))

● Functional Description: This script is a reference for Python Data Structures. It uses the type()
function to display the class of various variables, ranging from basic types like str, int, and float to
collection types like Tuples (parentheses), Lists (square brackets), and Dictionaries (curly braces with
key-value pairs).

10. [Link] & [Link]


Python

# From [Link]
num = input("Enter a number: ")
print("You entered:",num)
print("Data type of num:",type(num))

# From [Link]
n = int(input("How many roses?: "))
price = float(input("What is the price of each rose?: "))

● Functional Description: These scripts highlight Input Type Behavior. [Link] proves that
input() always treats data as a string (str) by default. [Link] demonstrates the fix: Type
Casting, where int() and float() are used to wrap the input so the data can be used for numerical
calculations.
VII. Advanced Conditional logic
11. if..else Statements5 Meet#[Link]
Python

number = int(input("Enter a number:"))


if number >=0:
if number==0:
print("The number is zero")
else:
print("The number is positive")
else:
print("The number is negative")

number = input("Enter a number:")


match number:
case 1:
print('one')
case 2|3:
print('two or three')
case _:
print("other number")

● Functional Description: This script showcases Nested If-Else logic and Combined Case Matching.
The first section uses an "if within an if" to distinguish between zero and positive numbers. The second
section uses a match statement with a Pipe operator (|), which allows a single code block to execute if
the input matches either 2 or 3.

12. if..else Quiz Meet#[Link]


Python

number = int(input("Enter a Number: "))


if number%2==0:
print(number,"is Even")
else:
print(number,"is Odd")

grade = int(input("Enter the grade: "))


if 90<=grade<=100:
print("Your grade of",grade,"is rated as an A")
elif 80<=grade<=89:
# ... additional ranges ...
else:
print("Your grade of",grade,"is rated as an F")
● Functional Description: This script demonstrates the Modulo Operator (%) and Chained
Comparison Operators. It uses number % 2 == 0 to check for divisibility (even vs. odd). For the
grading section, it uses a cleaner Python syntax (90<=grade<=100) to check if a value falls between
two numbers in a single expression.

VIII. Variable Assignment and Updates


13. if..else Statements2 Meet#[Link]
Python

number = int(input("Enter a number:"))


if number > 0:
print("The number is positive.")
else:
print("The number is negative.")

x=1
total=0
if x!=0:
total +=x
print(total)

● Functional Description: This script introduces the Addition Assignment Operator (+=). Instead of
writing total = total + x, it uses total += x to update the value of the variable in place. It also uses the
Not Equal To (!=) operator to verify if a variable holds a specific value before proceeding.

14. [Link] & [Link]


Python

# From [Link]
print("Hello World!")
x = 42
print(x)

# From [Link]
s = "Bob"
d = "Alice"
age = 25
city = "New York"
print(s, d, age, city)

● Functional Description: These are foundational scripts for Variable Initialization and Comma-
Separated Output. They show how to assign values to multiple variables and print them sequentially in
one line by separating them with commas.
IX. Detailed Calculation Logic
15. Meet#3 Lab Activity [Link]
Python

# (Logic identical to Loop Code 2 but without recursion)


a = (input("Enter Customer Name: "))
b = int(input("Number of kWh consumed: "))
# ... rate logic ...
f = d - e + 15
print("Total Bill:₱", f)

● Functional Description: This script focuses on Sequential Execution for business logic. It calculates
an electricity bill by: (1) determining the base rate per kWh, (2) calculating the base amount, (3)
applying a lifeline discount only if criteria are met, and (4) adding a constant meter charge of 15.0.
X. Business Logic and Formal Reporting
16. Meet#3 Lab [Link]
Python

a = (input("Enter employee name: "))


b = (input("Enter job position (Manager/Team Lead/Staff): "))
c = int(input("Enter the total hours worked: "))
d = (input("Enter withholding tax code(A/B/C): "))
print()
print("---PAYSLIP: Company ABC---")
print("Employee Name:",a)
print("Position:",b)
match b:
case "Manager":
e=500.0
case "Team Lead":
e=400.0
case "Staff":
e=300.0
case _:
e='Error, Check your input.'
print("Hourly Rate =₱",e)

if c>40:
f=(e*1.5)*(c-40)
print("Overtime Pay:₱",f)
else:
f=0
print("Overtime Pay: None, since time did not exceed 40 hours")

g=(40*e)+f
print("Gross Pay:₱",g)
# ... Deduction and Net Pay calculations ...

● Functional Description: This script is a structured Payroll Calculator.


● How it Functions: It uses a match-case block to assign an hourly rate based on a string input
(Position).
● Overtime Logic: It applies a conditional check for hours worked. If hours exceed 40, it calculates
overtime pay at a 1.5x multiplier for the extra hours.
● Deduction Logic: It uses another match-case to determine a percentage-based withholding tax and
subtracts fixed costs (SSS, Pag-IBIG, PhilHealth) to arrive at the Net Pay.
17. Meet#3 Lab Activity [Link]
Python

a = (input("Enter Customer Name: "))


b = int(input("Number of kWh consumed for 1 month: "))
print()
if 0<=b<=50:
c=5
elif 51<=b<=100:
c=6.5
elif 101<=b<=200:
c=7.5
elif 200<b:
c=8.5

d=b*c
if b<=50:
e=d*0.2
else:
e=0
f=d-e+15
print("---ELECTRICITY BILL---")
print("Customer:",a)
# ... Bill printouts ...
print("Total Bill:₱",f)

● Functional Description: This script calculates an Electricity Bill based on tiered consumption rates.
● Tiered Pricing: It uses an if-elif chain to assign a cost per kWh (c) depending on how much energy was
consumed.
● Conditional Discounting: It calculates a Lifeline Discount of 20% only if the consumption is 50 kWh
or less.
● Final Calculation: The total bill includes the base amount, minus any discount, plus a constant Meter
Charge of ₱15.0.
18. Meet Activity#4 Loop Code [Link]
Python

def main ():


a = (input("Enter employee name: "))
# ... (Payroll Logic similar to Lab Activity) ...

Repeat = input("Would you like to enter another employee? (yes/no):")


if Repeat == "yes":
main()
else:
print("Program has ended")
exit()

main()

● Functional Description: This is a Recursive Program Loop version of the payroll script.
● Structure: The code is wrapped inside a user-defined function called main().
● Repetition: Instead of using a while loop, this script uses Recursion by calling the main() function
again if the user types "yes" at the end.
● Termination: If the user types "no," the script uses the exit() command to stop execution entirely.

You might also like