Code Coach Solutions


Ballpark Orders[Pro]

Difficulty: Easy

Problem Statement:

You and three friends go to a baseball game and you offer to go to the concession stand for everyone. They each order one thing, and you do as well. Nachos and Pizza both cost $6.00. A Cheeseburger meal costs $10. Water is $4.00 and Coke is $5.00. Tax is 7%.

Task: 

Determine the total cost of ordering four items from the concession stand. If one of your friend’s orders something that isn't on the menu, you will order a Coke for them instead.


Input Format: 

You are given a string of the four items that you've been asked to order that are separated by spaces.


Output Format: 

You will output a number of the total cost of the food and drinks.


Sample Input: 

'Pizza Cheeseburger Water Popcorn'


Sample Output: 

26.75

Explanation:

Because Popcorn is not on the menu, this friend gets a coke which brings the subtotal to $25.00 and $26.75 with tax.


Solution:

s=input()
d={'Nachos':6,'Pizza':6,'Cheeseburger':10,'Water':4,'Coke':5} 
sum=0
for i in s.split():
     if i in d.keys():
         sum+=d[i]
     else: 
         sum+=5
 print(sum+(sum*7/100))

Explanation: 

The objective is to calculate the total cost along with the tax(For total cost). I come with the simple logic is that, iterate each word from the string and check whether it is present in the dictionary key. If it is present, sum the dictionary value otherwise sum with value 5. Then calculate the tax of the total sum and add with the total sum.

 

Result:

                           

Hope You understand the solution. The more you practice more you Learn. If there are any queries let us know in the comment section.

Tips to solve a problem in less time:

1. Don't read the whole problem statement initially. First, go through the input and output.

2. Mostly you will understand the problem while reading input, output, and Output explanation.

3. Now, Divide your Logic into 3 steps:

step1: Input & output

check whether you have written the correct syntax for input. To check you have to print the input.

step2: Build your own logic with proper indentation.

step3: Print the expected output.


Thank you!