You are on page 1of 6

I.

INTENDED LEARNING OUTCOMES

TLO1. Discuss the basic python syntax and variable


TLO2. Apply Linux OS in creating programs.

II. MATERIALS

Quantity Part Number Description


1 - Bootable VMware Software
1 - Bootable CentOS Linux ISO
1 set - Personal Computer with working hard
disk (at least 40GB)

III. PROBLEM

1. Create a simple calculator program for a cashier in a grocery. Your program will
require inputting the price of three items, the payment of the customer; and also if
the customer is a senior citizen or not. Use the following below as a reference for
your computation.
a. All items are subject to a 10% tax rate.
b. If the customer is a senior citizen, they have a discount of 20%
c. At the end of the program, display the change of the customer. Display also
if the payment of the customer is insufficient.
2. The basic rate of a bus is 10php for the first 1km and an additional 2php for every
succeeding 2kms. Input the distance the commuter will travel (in m), and the
payment. Display the total distance travel (in km), the cost of the travel, and the
change of the commuter. Display also if the payment of the commuter is not
sufficient.

For numbers 3-5: If the input voltage in the switch is 5V, it means it is ACTIVE. If the
input voltage is less than 5V, it means it is CUTOFF. If the input voltage is greater than
5V, it means it is BREAKDOWN. Assuming there are three switches SWA, SWB and
SWC;
3. The program will ask for an input voltage for the three switches, and display “LED
ON” if all switches are ACTIVE, otherwise, display “LED OFF”. (Do not use
logical operators)
4. The program will ask for an input voltage for the three switches, and display “LED
ON” if SWA is ACTIVE or both SWB and SWC are breakdowns. Otherwise,
display “LED OFF”. (Do not use logical operators)

2
5. The program will ask for an input voltage for the three switches, and display “LED
ON” if at least one of the switches is ACTIVE, otherwise, display “LED OFF”.

IV. Source Code

# 1. Create a simple calculator program for a cashier in a


# grocery. Your program will require inputting the price of
# three items, the payment of the customer; and also if the
# customer is a senior citizen or not. Use the following
# below as a reference for your computation.
# a. All items are subject to a 10% tax rate.
# b. If the customer is a senior citizen, they have a
# discount of 20%. At the end of the program, display the
# change of the customer. Display also if the payment of
# the customer is insufficient.

x = float(input("Enter price of item #1: "))


y = float(input("Enter price of item #2: "))
z = float(input("Enter price of item #3: "))
xT = x * 1.10
yT = y * 1.10
zT = z * 1.10
print "Initial: ", round(x + y + z, 3), "php"
print "Tax added: ", round((xT - x) + (yT - y) + (zT - z), 3), "php"
payment = float(input("Enter customer payment: "))
isSenior = str(raw_input("Is the customer senior? \nY = Yes \nN =
No\nAnswer: "))
if isSenior in ['y', 'Y']:
print("Customer is old!!!! They get 20% discount for being so old.")
xT *= 0.80
yT *= 0.80
zT *= 0.80
else:
print("Customer is young. They don't get discounts because they're
naughty.")
print "Total: ", round(xT + yT + zT, 3) , "php"
if ((xT + yT + zT) <= payment):
print "Customer's change is", round(payment - (xT + yT + zT),3), "php"
else:
print("Payment is not enough!")

3
# 2. The basic rate of a bus is 10php for the first 1km and
# an additional 2php for every succeeding 2kms. Input the
# distance the commuter will travel (in m), and the payment.
# Display the total distance travel (in km), the cost of
# the travel, and the change of the commuter. Display also
# if the payment of the commuter is not sufficient.
d = float(input("Commuter distance travelled (meters): "))
d *= 0.001 # conversion to km
payment = float(input("Commuter's payment: "))

cost = 10
if d >= 2:
cost += (int(d / 2) * 2)

print("Total distance travelled (km): " + str(round(d,3)))


print("Fare: " + str(cost))

if (payment >= cost):


print("Change: " + str(payment - cost))
else:
print("Payment not enough!")

# 1. all switches are ACTIVE, otherwise, display “LED OFF”.


# (Do not use logical operators)
swA = float(input("Enter voltage for switch A: "))
swB = float(input("Enter voltage for switch B: "))
swC = float(input("Enter voltage for switch C: "))

if swA == swB == swC == 5:


print("LED ON")
else:
print("LED OFF")
# 2. SWA is ACTIVE or both SWB and SWC are breakdowns.
# Otherwise, display “LED OFF”. (Do not use logical operators)
swA = float(input("Enter voltage for switch A: "))
swB = float(input("Enter voltage for switch B: "))
swC = float(input("Enter voltage for switch C: "))

if swB > 5 < swC:


print("LED ON")
elif swA == 5:
print("LED ON")
else:
print("LED OFF")

4
# 3. at least one of the switches is ACTIVE, otherwise,
# display “LED OFF”.
swA = float(input("Enter voltage for switch A: "))
swB = float(input("Enter voltage for switch B: "))
swC = float(input("Enter voltage for switch C: "))

if 5 in [swA, swB, swC]:


print("LED ON")
else:
print("LED OFF")

V. OUTPUT

5
CONCLUSION

6
REFERENCES

Rubrics:

Source Code and 80%


Output
Conclusion/References 20%
Total

You might also like