In: Computer Science
(Python Programming)
You are asked to develop a cash register for a fruit shop that sells oranges and apples. The program will first ask the number of customers. Subsequently, for each customer, it will ask the name of the customer and the number of oranges and apples they would like to buy. And then print a summary of what they bought along with the bill as illustrated in the session below:
How many customers? 2 Name of Customer 1 Harry Oranges are $1.40 each. How many Oranges? 1 Apples are $.75 each. How many Apples? 2 Harry, you bought 1 Orange(s) and 2 Apple(s). Your bill is $2.9 Name of Customer 2 Sandy Oranges are $1.40 each. How many Oranges? 10 Apples are $.75 each. How many Apples? 4 Sandy, you bought 10 Orange(s) and 4 Apple(s). Your bill is $17.0
#it will ask user to enter no of customer and store it in noOfCustomers
noOfCustomers = int(input("How many customers? "))
#as many customers we have, this loop will executes that many times
for i in range(noOfCustomers):
#it will ask for Customer's name and store it in name variable
name = input("Name of Customer " + str(i+1) + " ")
#displays cost of oranges
print("Oranges are $1.40 each.")
#it will ask user how many oranges needed and stored it in oranges
oranges = int(input("How many Oranges? "))
#displays cost of apples
print("Apples are $.75 each.")
#it will ask user how many apples needed and stored it in apples
apples = int(input("How many Apples? "))
#prints number of apples and oranges bought by customer
print(name + ", you bought " + str(oranges) +" Orange(s) and " + str(apples) + " Apple(s).")
#count a bill
amt = 1.40 * oranges + 0.75 * apples
#print a bill
print("Your bill is $" + str(amt))
Code Screenshots :
Output sample :