TYL - Food Corner Program

Food Corner Program.

We will make this program more robust after you learn try-catch.  For now, we will calculate for only 1 order.  Again, later you can use loops to calculate for many orders. 

As we have not learnt any data structures as lists, dictionaries etc, we will not use them now.

FoodCorner home delivers vegetarian and non-vegetarian combos to its customer based on order.

A vegetarian combo costs Rs.120 per plate and a non-vegetarian combo costs Rs.150 per plate. Their non-veg combo is really famous that they get more orders for their non-vegetarian combo than the vegetarian combo. Apart from the cost per plate of food, customers are also charged for home delivery based on the distance in kms from the restaurant to the delivery point. The delivery charges are as mentioned below:


Distance in kms          Delivery charge in Rs. Per kms

For first 3 kms                               0

For next 3 kms                                  3

For the remaining                              6


Given the type of food, quantity (no. of plates) and the distance in kms from the restaurant to the delivery point, write a python program to calculate the final bill amount to be paid by a customer.

The below information must be used to check the validity of the data provided by the customer:

Type of food must be ‘V’ for vegetarian and ‘N’ for non-vegetarian.

Quantity ordered should be minimum 1.

Distance in kms must be greater than 0.

If any of the input is invalid, the bill amount should be considered as -1.

A. Draw an abstract flow chart


B. Write the program



# Input: type of food(string-1 character), quantity (int), distance (float)
# Output : final bill
#Delivery charges in Rs. per km
first3=0
next3 = 3
remaining = 6
#costPerPlate
vegCombo = 120
nonVegCombo = 150
typeOfFood = input("Enter V-Vegetarian, N-Nonvegetarian: ")
quantity = int(input("How many plates? (minimum 1)?"))
distance = float(input("Enter the distance to your home: "))
       
bill = -1
if quantity !=0:
    if typeOfFood =='V' or typeOfFood == 'v':
        bill = vegCombo * quantity
    elif typeOfFood =='N' or typeOfFood == 'n':
        bill = nonVegCombo * quantity

# Add home delivery charges
homeDeliveryCharges = 0.0
if distance >=0 and distance <=3:
    homeDeliveryCharges = first3
elif distance >3 and distance<=6:
    homeDeliveryCharges = (distance-3)*next3
    finalBill = bill + homeDeliveryCharges
elif distance >6:
    homeDeliveryCharges = 3*next3
    homeDeliveryCharges += (distance-6)*remaining
    finalBill = bill + homeDeliveryCharges
else:
    finalBill = -1
   
print("Your final bill is Rs." + str(finalBill))





C. Solve the Test Cases.

Test Case 1:
Enter V-Vegetarian, N-Nonvegetarian: V
How many plates? (minimum 1)?5
Enter the distance to your home: 2
Your final bill is Rs.600

Test Case 2:
Enter V-Vegetarian, N-Nonvegetarian: V
How many plates? (minimum 1)?5
Enter the distance to your home: 5
Your final bill is Rs.606.0

Test Case 3:
Enter V-Vegetarian, N-Nonvegetarian: V
How many plates? (minimum 1)?5
Enter the distance to your home: 12
Your final bill is Rs.663.0

Test Case 4:
Enter V-Vegetarian, N-Nonvegetarian: v
How many plates? (minimum 1)?5
Enter the distance to your home: 12
Your final bill is Rs.645.0

Test Case 5:
Enter V-Vegetarian, N-Nonvegetarian: N
How many plates? (minimum 1)?3
Enter the distance to your home: 3
Your final bill is Rs.450

Test Case 6:
Enter V-Vegetarian, N-Nonvegetarian: N
How many plates? (minimum 1)?3
Enter the distance to your home: 6
Your final bill is Rs.459.0

Test Case 7:
Enter V-Vegetarian, N-Nonvegetarian: N
How many plates? (minimum 1)?3
Enter the distance to your home: 8
Your final bill is Rs.471.0

Test Case 8:
Enter V-Vegetarian, N-Nonvegetarian: c
How many plates? (minimum 1)?5
Enter the distance to your home: 4
Your final bill is Rs.-1

Test Case 9:
Enter V-Vegetarian, N-Nonvegetarian: N
How many plates? (minimum 1)?0
Enter the distance to your home: 5
Your final bill is Rs.-1

Test Case 10:
Enter V-Vegetarian, N-Nonvegetarian: N
How many plates? (minimum 1)?5
Enter the distance to your home: -2
Your final bill is Rs.-1

Comments

Post a Comment

Popular posts from this blog

TYL - Salary Hike - Python Problem

5 Questions for TYL on Strings(check if two string are anagrams)