Day 2: Operators

idimaimuna profile image M__ ・1 min read

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

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

#Sample Output

Posted on by:

idimaimuna profile



New programmer interested in web development and python as well. Aspiring to learn and be better than I started.


markdown guide