0% found this document useful (0 votes)
6 views3 pages

Python Lab: Variables & Conditionals

Uploaded by

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

Python Lab: Variables & Conditionals

Uploaded by

bronosamatt
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python Laboratory Activity (Challenging

Version)

Part 1: Variables and Data Types (3 Problems)


1. Student Information System
o Ask the user for their student ID (string), full name (string), 3 grades (float),
and section (string).
o Compute the average and display everything in a formatted report:
o Student Report:
o ID: 2025-001
o Name: Juan Dela Cruz
o Section: BSIT-2A
o Grades: 85.5, 90.0, 88.5
o Average: 88.0
2. Salary Calculator
o Input: employee name, basic salary, and number of overtime hours.
o Assume each overtime hour = ₱150.
o Compute gross salary, 12% tax, and net salary.
o Display results neatly formatted with 2 decimal places.
3. Online Shopping Cart
o Input: 3 product names, their quantities (int), and unit prices (float).
o Compute the total amount and display a mini receipt like:
o Cart Summary:
o 2 x Apples @ ₱50.00 = ₱100.00
o 1 x Milk @ ₱70.00 = ₱70.00
o 3 x Bread @ ₱35.00 = ₱105.00
o -------------------------------
o Total = ₱275.00

Part 2: Conditional Statements – if (3 Problems)


1. Leap Year Checker
o Input a year.
o Check if it’s a leap year:
 Divisible by 4 but not 100, OR divisible by 400.
o Print "Leap Year" or "Not a Leap Year".
2. Triangle Type Identifier
o Input three side lengths.
o Check and print whether it is:
 "Equilateral" (all equal)
 "Isosceles" (two equal)
 "Scalene" (all different)
 "Not a valid triangle" (triangle inequality fails).
3. Number Comparison Game
o Input 3 numbers.
o Print the largest number.
o Print whether it is even or odd.

Part 3: Conditional Statements – if-else (3 Problems)


1. Scholarship Eligibility
o Input: average grade and family income.
o If average ≥ 90 and income < ₱200,000 → "Full Scholarship".
o Else if average ≥ 85 and income < ₱500,000 → "Partial Scholarship".
o Else → "Not Eligible".
2. Electricity Bill Calculator
o Input kWh consumed.
o If consumption ≤ 100 → ₱5 per kWh.
o Else → ₱8 per kWh.
o Add ₱50 service charge.
o Print the total bill.
3. Username & Password Validation
o Input username and password.
o If username = "admin" and password = "12345", print "Login Successful".
o Else, print "Invalid Credentials".

Part 4: Conditional Statements – if-elif (3 Problems)


1. Bus Fare System
o Input age and destination zone (1, 2, 3).
o Zone base fares:
 Zone 1 → ₱20
 Zone 2 → ₱30
 Zone 3 → ₱40
o If age < 5 → "Free ride"
o If age 5–18 → 50% discount
o If age > 60 → 30% discount
o Else → pay full fare.
2. GPA to Letter Grade Converter
o Input GPA (0–4.0).
o Print:
 3.6–4.0 → "A"
3.0–3.59 → "B"
2.0–2.99 → "C"
1.0–1.99 → "D"
Below 1.0 → "F"
3. ATM Withdrawal Validator
o Input withdrawal amount.
o Rules:
 Must be a multiple of 100.
 Max withdrawal = ₱20,000.
 If valid, print "Transaction Successful".
 Else, print the reason: "Invalid amount" or "Exceeds limit".

Part 5: Conditional Statements – match (3 Problems)


1. Café Ordering System
o Input menu choice ("coffee", "tea", "juice", "water").
o Use match to display the price.
o Add ₱5 for take-out orders.
2. Grade Remarks with Match
o Input letter grade ("A", "B", "C", "D", "F").
o Use match to print remarks:
 A → "Excellent"
 B → "Very Good"
 C → "Good"
 D → "Fair"
 F → "Failed"
3. Currency Converter
o Input a currency code ("USD", "EUR", "JPY", "PHP").
o Use match to display the conversion rate to PHP (assume fixed rates).
o Multiply by amount entered.

Common questions

Powered by AI

To implement a leap year checker using conditional statements, you must check if the year is divisible by four but not by one hundred unless it is also divisible by four hundred. Specifically, the conditions are: if the year is divisible by 4 and not divisible by 100, or if it is divisible by 400, then it is a leap year .

A conditional system adapts bus fares by assessing age and destination zone, using base fare rates per zone (Zone 1: ₱20, Zone 2: ₱30, Zone 3: ₱40). Special age conditions offer adjustments: under 5s travel free, ages 5–18 receive a 50% discount, and over 60s a 30% discount. This necessitates branching logic that applies appropriate fares or additional reductions based on these distinct criteria .

Scholarship eligibility is determined using conditional statements evaluating average grade and family income. If a student’s average grade is 90 or above and family income is less than ₱200,000, they qualify for a full scholarship. If the average is 85 or higher, with income below ₱500,000, they qualify for a partial scholarship. Otherwise, the student is not eligible .

To calculate the total cost of items in an online shopping cart, multiply the quantity of each item by its unit price for individual totals, sum these to get the cart total, and format this data into a receipt. For example, use integers for quantities and floating-point numbers for unit prices to compute individual costs (e.g., 2 Apples x ₱50 = ₱100). Sum these for the total and display them in a formatted receipt style with a detailed list and final total underneath .

The triangle type identifier uses input of three side lengths to classify triangles. It checks the triangle inequality theorem: the sum of any two sides should be greater than the third side. If this fails, it’s 'Not a valid triangle'. If all sides are equal, it classifies as 'Equilateral'. If two sides are equal, it’s 'Isosceles'. If all sides differ, it’s 'Scalene' .

An ATM validates withdrawals by checking two conditions: the amount requested must be a multiple of 100, and it must not exceed the maximum limit of ₱20,000. If these conditions are met, the transaction is approved; if not, the system specifies the error, such as 'Invalid amount' or 'Exceeds limit' .

To convert a GPA into a letter grade, compare the GPA against predefined ranges: GPA of 3.6–4.0 translates to an 'A', 3.0–3.59 to 'B', 2.0–2.99 to 'C', 1.0–1.99 to 'D', and below 1.0 to 'F'. The conversion must ensure proper matching using logical bounds to assign the correct letter .

Challenges include ensuring data security and preventing unauthorized access. A basic system verifies login credentials by checking if the input matches preset conditions: username equals 'admin' and password equals '12345'. If these match, access is granted with 'Login Successful'; otherwise, it returns 'Invalid Credentials' .

An electricity bill is calculated by multiplying the kWh consumed by the rate per kWh (₱5 if ≤ 100, otherwise ₱8), then you add a fixed service charge of ₱50. This ensures correctness by clearly distinguishing between variable and non-variable charges while calculating the total billing amount .

The salary calculator must consider the employee's basic salary, overtime hours, and apply deductions. First, calculate overtime pay by multiplying the number of overtime hours by a fixed rate (e.g., ₱150 per hour). Then, sum the basic salary and overtime pay to find the gross salary. Apply a 12% tax on the gross salary to find taxable deductions and subtract this amount from the gross salary to determine the net salary. Results should be displayed neatly, formatted to two decimal places .

You might also like