Discount Price Calculator – Q&A

Question 1[10 marks]
Oksana has created the following program in her computer science lesson. The aim of this program is to calculate the price after discount of a list of products bought by a customer.

Here is her Python code:
#Discount Price Calculator
def calculateDiscount(price,percentageDiscount):
  discount = price * percentageDiscount / 100
  discount = round(discount,2)
  return discount

#Main Program  
item = input("Enter the name of the item to buy? or X to quit!")
while item!="X":
  itemPrice=float(input("Enter a price for your item: £"))
  percentageDiscount = int(input("Enter a percentage discount for your item: %"))
  discount = calculateDiscount(itemPrice, percentageDiscount)
  newPrice = itemPrice - discount
  print("Discounter price: £" + str(newPrice))
  item = input("Enter the name of another item to buy? or X to quit!")


To help Oksana use the right terminology when annotating and explaining what her code does, you will need to answer the following 10 questions:

  1. What is the identifier of the subroutine defined in this code?
  2. Is this subroutine a procedure or a function? Why?
  3. How many parameters does this subroutine take?
  4. What programming construct is this subroutine based on: sequencing, selection or iteration?
  5. Which line of code will be executed first by the computer when you run this code?
  6. What programming construct is the main program based on: sequencing, selection or iteration?
  7. Can you identify three variables used in the main program?
  8. What is the data type of item?
  9. What is the data type of discount?
  10. On which line of code is string concatenation used?
1) 
2) 
3) 
4) 
5) 
6) 
7) 
8) 
9) 
10) 
Question 2[4 marks]
Without rewriting the above code, explain how Oksana could improve this code further to calculate and output the total discounted cost of all the items being bought by a customer?
Save / Share Answers as a link
unlock-access

Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
➤ Members' Area

Did you like this challenge?

Click on a star to rate it!

Average rating 2.8 / 5. Vote count: 24

No votes so far! Be the first to rate this post.

As you found this challenge interesting...

Follow us on social media!