Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

Republic of the Philippines

BATANGAS STATE UNIVERSITY


The National Engineering University
Alangilan Campus
Golden Country Homes, Alangilan, Batangas City, Batangas, Philippines 4200
Tel Nos.: (+63 43) 425-0139 loc. 2121 / 2221
E-mail Address: ceafa@g.batstate-u.edu.ph | Website Address: http://www.batstate-u.edu.ph

College of Engineering, Architecture and Fine Arts

CIVIL ENGINEERING PROGRAM


CpE 402: COMPUTER PROGRAMMING 2
LABORATORY #1

Name: Carlo P. Gonzales Section: BSIE-2106


Sr-Code: 21-05216

DECISION STRUCTURES

Create a phyton program for the following given:

A. Book Club Points


Serendipity Booksellers has a book club that awards points to its customers based on the
number of books purchased each month. The points are awarded as follows:
 If a customer purchases 0 book, he or she earns 0 points.
 If a customer purchases 1 book, he or she earns 5 points.
 If a customer purchases 2 books, he or she earns 10 points.
 If a customer purchases 3 books, he or she earns 20 points.
 If a customer purchases 4 or more books, he or she earns 40 points.

Code:
number_of_books = int(input("Enter the number of books purchased: "))
message = ""

if number_of_books < 0:
message = "Error. Enter a positive number. \n" + \
"Re-run program and try again."
else:
message = "You are awarded "

if number_of_books >= 0 and number_of_books <= 1:


message += "0 "
elif number_of_books >= 2 and number_of_books <= 3:
message += "5 "
elif number_of_books >= 4 and number_of_books <= 5:
message += "15 "
elif number_of_books >= 6 and number_of_books <= 7:
message += "30 "
elif number_of_books >= 8:
message += "60 "

message += "points."

Leading Innovations, Transforming Lives


print(message)

B. Software Sales
A software company sells a package that retails for $199. Quantity discounts are given
according to the following table:
Quantity Discount
10–19 5%
20–49 10%
50–99 20%
100 or more 50%
Design a program that asks the user to enter the number of packages purchased. The program
should then display the amount of the discount (if any) and the total amount of the purchase after
the discount.

Leading Innovations, Transforming Lives


Code:
PRICE_PER_PACKAGE = 199.00

number_of_packages = float(input('\nEnter # of packages purchased: '))

display_message = ""

if number_of_packages < 0:
display_message = "Error. # of packages must be greater than 0.\nRe-run program and try
again."
else:
discount_percentage = 0

if number_of_packages < 10:


discount_percentage = 0
elif number_of_packages >= 10 and number_of_packages <= 19:
discount_percentage = .5 # 5%
elif number_of_packages >= 20 and number_of_packages <= 49:
discount_percentage = .10 # 10%
elif number_of_packages >= 50 and number_of_packages <= 99:
discount_percentage = .30
elif number_of_packages >= 100:
discount_percentage = .50 # 50%

package_total = number_of_packages * PRICE_PER_PACKAGE


discount_amount = (package_total) * discount_percentage
grand_total = package_total - discount_amount
display_message = "Package total = $" + format(package_total, ',.2f') + \
"\nDiscount Percentage = " + format(discount_percentage, '.0%') + \
"\nDiscount amount = $" + format(discount_amount, ',.2f') + \
"\nGrand total = $" + format(grand_total, ',.2f')

print("\n" + display_message + "\n")

Leading Innovations, Transforming Lives


C. Grading System

Write a program that will allow a student to enter four (4) test score and then average the inputted test
scores and display the numeric equivalent grade for that score.

Leading Innovations, Transforming Lives


Note:
 Program is to ask the users Full name, Course Major and sr-code.
 Grade limit input is 0 to 100.
 Four input grades as input: (prelim, midterm, semis, finals).
 If input grades are not complete, display INC or Incomplete.
 Create a congratulatory text with respect to the given table.
 Print all values.

Code:
# Declaring Variables
FullName = input("Enter your FullName:")
Course = input("Enter your Course Major:")
Subject = input("Enter your Sr-code:")
PrelimGrade = input("Enter your PrelimGrade:")
MidtermGrade = input("Enter your MidtermGrade:")
SemisGrade= input("Enter your SemisGrade:")
FinalGrade = input("Enter your FinalGrade:")

# Simulation of Variables

print("Name:"+str(FullName))
print("Course:"+str(Course))
print("Subject:"+str(Subject))
print("PG:"+str(PrelimGrade))
print("MG:"+str(MidtermGrade))
print("FG:"+str(FinalGrade))

# Computation for Grade


result1 = float(PrelimGrade)*.25
result2 = float(MidtermGrade)*.25
result3 = float(SemisGrade)*.25
result4 = float(FinalGrade)*.25
semestralGrade = (float(result1)+float(result2)+float(result3))+float(result4)
print("SG="+str(semestralGrade))

# Conditional statement
if (semestralGrade >= 0) and (semestralGrade <= 74):
print("Remarks:FAILED")
print("Just work harder next time and you will be fine.")
elif (semestralGrade >= 75) and (semestralGrade <= 100):
print("Remarks:PASSED")
print("Congratulations you did great!")
elif (semestralGrade >= 101) or (semestralGrade <= 0):
print("Remarks:INC")

Leading Innovations, Transforming Lives


Leading Innovations, Transforming Lives
Attache your codes and screenshots of simulation here:

A. Book Club Points

- (insert here)

B. Software Sales

- (insert here)

C. Grading System

- (insert here)

Leading Innovations, Transforming Lives

You might also like