A Shamelessly Simple E-Restaurant Order

mix vegan sala online restaurant order form
#100DaysofCode

Shopify gets your restaurant online fast. So you can keep cooking without sacrificing what matters.

To get started, a shamelessly simple open-source Python implementation of the above restaurant online order system is discussed.

The simplest restaurant online order system using Python functions is described as follows:

Check input numeric validation

def numeric_validation(value):
“”””
This function take an input as interger
and validate that it takes onlu numeric data.
“””
while True:
try:
val = int(input(value))
except:
print(‘Please use numeric digits.’)
continue
if val < 0:
print(‘Please enter a positive number.’)
continue
else:
break
return val

Add Order items

def order_items(orders):
order_items.total_price = 0
run = True
while run:
orderList = orders
items = numeric_validation(“Enter Item No:”)
if (items in orderList):
print(“Already ordered!!! Try Somthing New”)
continue
else:
items_no = int(items)
qty = numeric_validation(“Quantity:”)
order_items.total_price += (menue[items_no][‘price’] * qty)
orderList.append(menue[items_no][‘item’])
order = input(“Do you want to order more? y/n:”)
if order == ‘y’:
continue
else:
run = False
return order_items

Let’s start main function

print(“#”30+”\n Welcome To DigHiSci Cafe\n”+”#”30+ \
“\nPlease Chose your Order Number:”)

Declare Variables

menue = { 1:{“item”:”tea”,”price”:1},
2:{“item”:”coffee”,”price”:2},
3:{“item”:”sandwich”,”price”:4},
4:{“item”:”salad”,”price”:6}
}

orders = [] # issue it has to be a dictionary not a list
qty= 1

Show menu

for item,value in menue.items():
print(“No#”,item,”: Item: “,value[“item”].title(),”- Price:”+str(value[“price”])+”$”)
print(‘#’*30)

Add item

order_items(orders)
print(‘#’*30)

Show card list

print(“You ordered the following Items: “)
for i in range(len(orders)):
print(str(i+1)+”- “+orders[i].title())
print(“-“*30+”\nYour Total Price: “+str(order_items.total_price)+”$”)

End

print(‘#’*30+”\nGreat Thanks! Order Again.\n”)

Here is the result:

##############################
    Welcome To DigHiSci Cafe
##############################
Please Chose your Order Number:
No# 1 : Item:  Tea - Price:1$
No# 2 : Item:  Coffee - Price:2$
No# 3 : Item:  Sandwich - Price:4$
No# 4 : Item:  Salad - Price:5$
##############################
Enter Item No:1
Quantity:1
Do you want to order more? y/n:y
Enter Item No:2
Quantity:1
Do you want to order more? y/n:y
Enter Item No:3
Quantity:1
Do you want to order more? y/n:y
Enter Item No:4
Quantity:1
Do you want to order more? y/n:n
##############################
You have ordered the following Items: 
1- Tea
2- Coffee
3- Sandwich
4- Salad
------------------------------
Your Total Price: 12$
##############################
Great Thanks! Order Again.

Voilà!

Bon appétit!

Appendix: Full Script

# check input numeric validation
def numeric_validation(value):
    """"
    This function take an input as interger
    and validate that it takes onlu numeric data. 
    """
    while True:
        try:
            val = int(input(value))
        except:
            print('Please use numeric digits.')
            continue
        if val < 0:
            print('Please enter a positive number.')
            continue
        else:
            break
    return val
# Add Order items
def order_items(orders):
    order_items.total_price = 0
    run = True
    while run:
        orderList = orders
        items = numeric_validation("Enter Item No:")
        if (items in orderList):
            print("Already ordered!!! Try Somthing New")
            continue
        else:
            items_no = int(items)
            qty = numeric_validation("Quantity:")  
            order_items.total_price += (menue[items_no]['price'] * qty)
            orderList.append(menue[items_no]['item'])
            order = input("Do you want to order more? y/n:")
            if order == 'y':
                continue
            else:
                run = False
    return order_items   
## Start main function
print("#"*30+"\n    Welcome To DigHiSci Cafe\n"+"#"*30+ \
"\nPlease Chose your Order Number:")

# Declare Variables
menue = { 1:{"item":"tea","price":1},
2:{"item":"coffee","price":2},
3:{"item":"sandwich","price":4},
4:{"item":"salad","price":5}
}

orders = [] # issue it has to be a dictionary not a list
qty= 1

# Show menue
for item,value in menue.items():
    print("No#",item,": Item: ",value["item"].title(),"- Price:"+str(value["price"])+"$")
print('#'*30)

# Add item 
order_items(orders)
print('#'*30)

# Show card list
print("You have ordered the following Items: ")
for i in range(len(orders)):
    print(str(i+1)+"- "+orders[i].title())
print("-"*30+"\nYour Total Price: "+str(order_items.total_price)+"$")

#End    
print('#'*30+"\nGreat Thanks! Order Again.\n") 
  • Example Output:
##############################
    Welcome To DigHiSci Cafe
##############################
Please Chose your Order Number:
No# 1 : Item:  Tea - Price:1$
No# 2 : Item:  Coffee - Price:2$
No# 3 : Item:  Sandwich - Price:4$
No# 4 : Item:  Salad - Price:5$
##############################
Enter Item No:1
Quantity:2
Do you want to order more? y/n:n
##############################
You have ordered the following Items: 
1- Tea
------------------------------
Your Total Price: 2$
##############################
Great Thanks! Order Again.

Go back

Your message has been sent

Warning

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

€5.00
€15.00
€100.00
€5.00
€15.00
€100.00
€5.00
€15.00
€100.00

Or enter a custom amount


Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

Discover more from Our Blogs

Subscribe to get the latest posts sent to your email.

Leave a comment

Discover more from Our Blogs

Subscribe now to keep reading and get access to the full archive.

Continue reading