Day 2: Operators

idimaimuna

M__

Posted on June 12, 2020

Day 2: Operators

Hey there,
Currently I'm on Day 2 of HackerRank's 30 days of code challenge and usually after getting the introduction to programming and learning about the various datatypes, the next step is usually to familiarize oneself with operators.
Operators are symbols that are used to work on various operands(the variables or values). They are three basic types of operators:

  1. Unary ( used with 1 operand)
  2. Binary ( used with 2 operands)
  3. Ternary (used with 3 operands)

The next branch breaks down the operators on the basis of functionality:

Arithmetic Operators: used to perform mathematical operations:

  1. (+) Addition
  2. (-) Subtraction
  3. (*) Multiplication
  4. (/) Division; This gives the result as a float if a float value is used)
  5. (%) Remainder/Modulus
  6. (//) Integer Division; This gives the result as an integer if a float value is used)

Conditional Operators: used to compare two conditions:

  1. (>) Greater than
  2. (<) Less than
  3. (>=) Greater than or equal to
  4. (<=) Less than or equal to
  5. (==) Equal

Logical Operators: used to compare multiple conditions at the same time:

  1. (and)
  2. (or)

Today's task was to find a meal's total cost given the meal price, tip percent and tax percent and my solution was:

 def solve(meal_cost, tip_percent, tax_percent):

    tip = meal_cost * (tip_percent/100)
    tax = meal_cost * (tax_percent/100)

    total_meal = meal_cost + tip + tax
    print(round(total_meal))

# Calling the function: solve(12.00, 20, 8)
#Sample Input
#12.00
#20
#8

#Sample Output
#15
Enter fullscreen mode Exit fullscreen mode
💖 💪 🙅 🚩
idimaimuna
M__

Posted on June 12, 2020

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related

How to level up your backend skills
webdev How to level up your backend skills

November 16, 2024

Hello DEV Community!
cybersecurity Hello DEV Community!

September 5, 2024

Conditions (If-else-elif) Part-08
beginners Conditions (If-else-elif) Part-08

September 4, 2024