# Italian Takeaway Ordering System

An Italian Takeaway is asking you to write a computer program to facilitate the ordering process and automatically calculate the total cost of an order.

They have stored their menu and all prices into a text file with the following information:

Code;Description;Price;

When a customer order food, they give the lists of codes they would like order. For instance a customer could order the following: S4,P3,P7,X2,D4,C1,W2

Your program should allow the customer to order as many options from the menu as they need. For each option, it should lookup the price in the text file provided. It should then calculate and output the total cost of the order.

To complete this challenge you will need to read more about how to read through a CSV file.

#### Testing

Once you have completed the code check that it produces the expected output by performing the following tests:

 Test # Input Values Expected Output Actual Output #1 S4,P3,P7 £28.89 #2 P10,S1 £16.00 #3 P4,D2,C2 £19.30

Add some input validation routines to your code so that the customer can only enter a valid code from the menu.

#### Video Tutorial / Solution

[pms-restrict display_to=”not_logged_in” message=” “]

#### Solution...

The solution for this challenge is available to full members!
Find out how to become a member:
[/pms-restrict] [pms-restrict subscription_plans=”14217″ message=” “]

#### Solution...

You are viewing this solution as part of your full membership subscription!

Python Code

#### Python Code

```#Italian Takeaway Ordering System
print(" ~~~~~~~~~~~~~~~~~~~~~~~ ")
print("|    Italian Takeway    |")
print("|    Ordering System    |")
print(" ~~~~~~~~~~~~~~~~~~~~~~~ ")
print("")
print("Welcome to our takeway ordering system.")
print("Type X to exit.")

code = input("Enter the option code you would like to order: (e.g.P1)")

totalCost = 0
while (code!="X"):
#Start Linear search through the text file
itemFound=False
for line in file:
#Extract the data stored on this line
data = line.split(";")
itemCode = data[0]
itemDescription = data[1]
itemPrice = float(data[2])

#Is this the item we are looking for?
if itemCode == code:
itemFound=True
print(itemCode + " - " + itemDescription + " - £" + str(itemPrice))
totalCost = totalCost + itemPrice

if not itemFound:
print("Item code does not exist.")
code = input("Enter another code or X to exit.")

print("Total cost of your order: £" + str(totalCost))
print("Good bye!")

file.close()
```
[/pms-restrict]

Did you like this challenge?

Click on a star to rate it!

Average rating 4.3 / 5. Vote count: 30

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

As you found this challenge interesting...