You are on page 1of 5

De La Salle University - Dasmariñas 1

CEAT – Engineering Department

T-CPET121LA – Introduction to Computational Thinking


PROBLEM SETS A
Name: ____________________________________________________________
Year and Section: _______________________ Date: _______________________ Rating:

INSTRUCTION: Upload this document (as PDF file) with your python code and output screenhot as your answer.

1. Andrew, Andrei and Andres are engineering classmates looking for a dormitory to stay for the coming school year.
They will share the monthly payment for the dormitory according to their agreement. This is their agreement.
Andrew will pay 40%, Andrei will pay 35% while Andres will pay the remaining balance. Create a program that will
ask for the monthly rate of the dormitory, and will display the following:
a. How much is the total monthly contribution of Andrew, Andrei and Andres.
b. How much is the total rent in the dormitory for the whole school year, assuming it will last for 10 months
c. How much will Andrew, Andrei and Andres prepare for the whole school year

monthlyrate = float(input("Enter the monthly rate of the dormitory: "))

andrewcontribution = monthlyrate * 0.4


andreicontribution = monthlyrate * 0.35
andrescontribution = monthlyrate - andrewcontribution - andreicontribution

totalmonthlycontribution = andrewcontribution + andreicontribution + andrescontribution


print("The total monthly contribution is:", totalmonthlycontribution)

totalrent = monthlyrate * 10
print("The total rent for the whole school year is:", totalrent)

totalprepayment = totalmonthlycontribution * 10
print("The total prepayment for the whole school year is:", totalprepayment)

Paste program output screenshot here*

T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 2
CEAT – Engineering Department

2. Create a python script for a simple cashier system that will satisfy the following conditions.
a. Input the price of three items the customer bought in a department store, as well as the customer’s
payment.
b. A customer will have a 20% discount if the total amount rendered is greater than 5000php.
c. Get the tax of 10% from the discounted price
d. If the payment is insufficient, display “Insufficient Funds”
e. If the payment is exact amount, display “Thank you for giving an exact amount”
f. Display the change of the transaction

item1 = float(input("Enter the price of item 1: "))


item2 = float(input("Enter the price of item 2: "))
item3 = float(input("Enter the price of item 3: "))
total = item1 + item2 + item3
payment = float(input("Enter the payment amount: "))

if total > 5000:


discount = 0.2 * total
else:
discount = 0

discounted = total - discount


tax = 0.1 * discounted

total_amount = discounted + tax

if payment < total_amount:


print("Insufficient Funds")
elif payment == total_amount:
print("Thank you for giving an exact amount")
else:
change = payment - total_amount
print(f"Change: {change:.2f} PHP")

3. Create a simple calculator. Your python script will require you to input two numbers and the keyword that
corresponds to the arithmetic operator to be performed, and then display the result. The following below are the
keyword with the operators to be used. Display “ERROR” if the user input wrong operator.
ADD – Addition SUB – Subtraction
MUL – Multiplication DIV – Division (show separately the remainder)
num1 = float(input("first number: "))
num2 = float(input("second number: "))
operator = input("operator? (ADD, SUB, MUL, DIV): ")

if operator == "ADD":
result = num1 + num2
elif operator == "SUB":
result = num1 - num2
elif operator == "MUL": T-CPET121LA
result = num1 * num2 Introduction to Computational Thinking
elif operator == "DIV":
if num2 == 0:
print("ERROR: Cannot divide by zero")
De La Salle University - Dasmariñas 3
CEAT – Engineering Department

4. The fuel tank capacity of Car A is 20L, Car B is 30L and Car C is 35L. Your script will ask for an input price per
liter
pricediesel = float(input("Enter price per liter of diesel: "))
of
priceunleaded = float(input("Enter price per liter of unleaded: "))

tanka = 20
tankb = 30
tankc = 35

diesela = tanka * pricediesel


dieselb = tankb * pricediesel
dieselc = tankc * pricediesel

unleadeda = tanka * priceunleaded


unleadedb = tankb * priceunleaded
unleadedc = tankc * priceunleaded

print("Worth of diesel fuel needed:")


print("CarA:$",diesela,)
print("CarB:$",dieselb,)
print("CarC:$",dieselc,)

print("WOrth of unleaded fuel needed:")


print("CarA:$",unleadeda,)
print("CarB:$",unleadedb,)
print("CarC:$",unleadedc,)
print("The result of" ,num1, operator, num2, "is" ,result,)
T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 4
CEAT – Engineering Department

diesel and unleaded; and display how much is needed of each car for a full tank, both for diesel and unleaded.

5. Input three numbers, display the LARGEST number among the three.

num1 = float(input("Enter first number: "))


num2 = float(input("Enter second number: "))
num3 = float(input("Enter third number: "))
largest = num1
if num2 > largest:
largest = num2
if num3 > largest:
largest = num3

print("The largest number is:", largest)

6. Search on available resources regarding Python Logical Operators/Compound Statements. Complete the table
below.
Logical Explain how does this logical operator works. When will it return a
Symbol
Operator TRUE?

AND ‘and’ If both operands is true then its true if not then its false
OR ‘or’ The operator needs at least 1 true to be true otherwise its false
NOT ‘not’ If operand is true the its false and vice versa

7. Input three numbers, display the LARGEST number among the three. (Use Logical Operator)

T-CPET121LA
Introduction to Computational Thinking
De La Salle University - Dasmariñas 5
CEAT – Engineering Department

A = float(input("1st number: "))


B = float(input("2nd number: "))
C = float(input("3rd number: "))

if (A >= B) and (A >= C):


largest = A
elif (B >= A) and (B >= C):
largest = B
else:
largest = C

print("The largest number is", largest)

T-CPET121LA
Introduction to Computational Thinking

You might also like