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

2210_w20_PM_22

Friday, June 26, 2020 5:57 PM

2210_w20_PM_22

Lbb Page 1
Lbb Page 2
Lbb Page 3
//Use arrays to store item code, description and price
ShoppingCart=[]
DECLARE Item_Code[17]: STRING =["A1", "A2", "B1", "B2", "B3", "C1",
"C2", "C3", "D1", "D2", "E1","E2","E3", "F1", "F2", "G1", "G2"]

DECLARE Description[17]: STRING= ["Compact", "Tower", "8GB",


"16GB", "32GB", "1 TB HDD", "2 TB HDD", "4 TB HDD", "240 GB SSD",
"480 GB SSD", "1 TB HDD", "2 TB HDD", "4 TB HDD", "DVD/Blu-Ray
Player", "DVD/Blu-Ray Re-Writer", "Standard Version", "Professional
Version"]

Lbb Page 4
DECLARE Price[17]: REAL= [75.00, 150.00, 79.99, 149.99, 299.99,
49.99, 89.99, 129.99, 59.99, 119.99, 49.99, 89.99, 129.99, 50.00,
100.00, 100.00, 175.00]

CONSTANT Basic_Price=200
DECLARE Computer-Price, Case_Price, RAM_Price, MHDD_Price: REAL
// Allow a customer to choose one case, one RAM and one HDD

PRINT "Here is the list of Computer Case"


FOR Index=0 TO 1
Print Item_Code[Index], Description[Index], Price[Index]
NEXT Index
PRINT "Enter Item code for Case "
INPUT Case_Code

WHILE NOT (Case_Code=Item_Code[0] OR Case_Code=Item_Code[1]) DO


Print "Error! Case code is not valid, try again"
INPUT Case_Code
ENDIF

PRINT "Here is the list of Computer RAM"


FOR Index=2 TO 4
Print Item_Code[Index], Description[Index], Price[Index]
NEXT Index
PRINT "Enter Item code for RAM "
INPUT RAM_Code

WHILE NOT (Case_Code=Item_Code[0] OR Case_Code=Item_Code[1]) DO


Print "Error! Case code is not valid, try again"
INPUT Case_Code
ENDIF

FOR Index = 0 TO 7
IF Case_Code=Item_Code[Index] THEN
Case_Price <-- Price[Index]
ShoppingCart.append(Description[index])

IF RAM_Code=Item_Code[Index] THEN RAM_Price<--Price[Index]


IF MHDD_Code=Item_Code[Index] THEN MHDD_Price<--Price[Index]
NEXT Index
Computer_Price<-- Basic_Price + Case_Price + RAM_Price +

Lbb Page 5
Computer_Price<-- Basic_Price + Case_Price + RAM_Price +
MHDD_Price
PRINT "Computer price = " , Computer_Price

Python Code:
Item_Code=["A1", "A2", "B1", "B2", "B3", "C1", "C2", "C3", "D1", "D2",
"E1","E2","E3", "F1", "F2", "G1", "G2"]
Description= ["Compact", "Tower", "8GB", "16GB", "32GB", "1 TB HDD",
"2 TB HDD", "4 TB HDD", "240 GB SSD", "480 GB SSD", "1 TB HDD", "2
TB HDD", "4 TB HDD", "DVD/Blu-Ray Player", "DVD/Blu-Ray Re-
Writer", "Standard Version", "Professional Version"]
Price= [75.00, 150.00, 79.99, 149.99, 299.99, 49.99, 89.99, 129.99,
59.99, 119.99, 49.99, 89.99, 129.99, 50.00, 100.00, 100.00, 175.00]
Basic_Price=200
print("Here is the list of Computer Case")
for Index in range(2):
print(Item_Code[Index], Description[Index], Price[Index])

Case_Code=str(input("Enter Item code for Case: "))

while not (Case_Code==Item_Code[0] or Case_Code==Item_Code[1]):


print("Error! Case code is not valid, try again")
Case_Code=str(input("Enter a valid case code "))

print("Here is the list of RAM:")


for Index in range(2, 5):
print(Item_Code[Index], Description[Index], Price[Index])

RAM_Code=str(input("Enter Item code for RAM: "))


while not (RAM_Code==Item_Code[2] or RAM_Code==Item_Code[3] or
RAM_Code==Item_Code[4]):
print("Error! RAM code is not valid, try again")
RAM_Code=str(input("Enter a valid RAM code "))

print("Here is the list of Main Hard Disc Drive:")


for Index in range(5, 8):
print(Item_Code[Index], Description[Index], Price[Index])

MHDD_Code=str(input("Enter Item code for Main Hard Disc Drive: "))

Lbb Page 6
MHDD_Code=str(input("Enter Item code for Main Hard Disc Drive: "))

while not (MHDD_Code==Item_Code[5] or MHDD_Code==Item_Code[6] or


MHDD_Code==Item_Code[7]):
print("Error! Main hard disc drive code is not valid, try again")
MHDD_Code=str(input("Enter a valid Main Hard Disc Drive code "))

# selection of chosen items


for Index in range(8):
if Case_Code==Item_Code[Index]: Case_Desc=Description[Index]
if RAM_Code==Item_Code[Index]: RAM_Desc=Description[Index]
if MHDD_Code==Item_Code[Index]: MHDD_Desc=Description[Index]
# Calculating computer price
for Index in range(8):
if Case_Code==Item_Code[Index]: Case_Price=Price[Index]
if RAM_Code==Item_Code[Index]: RAM_Price=Price[Index]
if MHDD_Code==Item_Code[Index]: MHDD_Price=Price[Index]

Computer_Price= Basic_Price + Case_Price + RAM_Price + MHDD_Price


print("List of chosen items:")
print("Case = ", Case_Desc)
print("RAM = ", RAM_Desc)
print("Main Hard Disc Drive = ", MHDD_Desc)

print("Computer price = " , Computer_Price)

Count_Addition=0
PRINT "Do you want to purchase a solid state drvie (Yes/No) :"
INPUT Choice
IF Choice="Yes" THEN
PRINT "Here is the list of solid state drive "
FOR Index= 8 TO 9
PRINT Item_Code[Index], Description[index], Price[Index]
NEXT Index
PRINT "Enter item code of selected solid state drive "
INPUT SSD_Code
WHILE NOT (SSD_Code=Item_Code[8] or SSD_Code=Item_Code[9]) DO
PRINT "Error! Invalid item code for SSD is entered, try
again"
INPUT SSD_Code
ENDWHILE

Lbb Page 7
ENDWHILE
ENDIF
PRINT "Do you want to purchase a solid state drvie (Yes/No) :"
INPUT Choice
IF Choice="Yes" THEN
PRINT "Here is the list of solid state drive "
FOR Index= 8 TO 9
PRINT Item_Code[Index], Description[index], Price[Index]
NEXT Index
PRINT "Enter item code of selected solid state drive "
INPUT SSD_Code
WHILE NOT (SSD_Code=Item_Code[8] or SSD_Code=Item_Code[9]) DO
PRINT "Error! Invalid item code for SSD is entered, try
again"
INPUT SSD_Code
ENDWHILE
ENDIF

Lbb Page 8

You might also like