Arithmetic Operators

There are 5 types of arithmetic operator used for binary operation:

  • +: Additive
  • -: Subtraction
  • *: Multiplication
  • /: Division
  • %: Remainder (modulo)

+: Additive operator add two numbers

– : Subtraction operator subtract one number from another.

*: Multiplication operator multiply two numbers.

/: Division operator divides one number from another.

%: Remainder or modulo operator returns remainder after dividing one number from other.

In this challenge, we’ll work with arithmetic operators. Check out the Tutorial tab for learning materials and an instructional video!

Given the meal price (base cost of a meal), tip percent (the percentage of the meal price being added as tip), and tax percent (the percentage of the meal price being added as tax) for a meal, find and print the meal’s total cost.

Note: Be sure to use precise values for your calculations, or you may end up with an incorrectly rounded result!

Input Format

There are  lines of numeric input:
The first line has a double,  mealCost (the cost of the meal before tax and tip).
The second line has an integer, tipPercent (the percentage of  being added as tip).
The third line has an integer, taxPercent (the percentage of  being added as tax).

Output Format

Print The total meal cost is totalCost dollars., where totalCost is the rounded integer result of the entire bill (mealCost with added tax and tip).

Sample Input


Sample Output

The total meal cost is 15 dollars.


def get_total_cost_of_meal():
# original meal price
meal_cost = float(input())
# tip percentage
tip_percent = int(input())
# tax percentage
tax_percent = int(input())
# Write your calculation code here
tip = meal_cost * tip_percent / 100 tax = meal_cost * tax_percent / 100
total_cost = int(round(meal_cost + tax + tip))
return str(total_cost)
# Print your result
print("The total meal cost is " + get_total_cost_of_meal() + " dollars.")
Code For day 2 HackerRank 30 Days of Code Challenge

Here we have defined a function ‘get_total_cost_of_meal’. To know more about python function and how to define it visit here. Basically function is a organised piece of code which is reused to perform single task. It is defined by using ‘def’ then the name of the function followed by parenthesis ‘()’.

Inside the ‘get_total_cost_of_meal’ function we have taken three inputs from user. The three inputs are used to calculate the actual price of the meal after paying taxes and tip. The total cost is then print out.

Leave a Reply

Your email address will not be published.