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:
- Unary ( used with 1 operand)
- Binary ( used with 2 operands)
- Ternary (used with 3 operands)
The next branch breaks down the operators on the basis of functionality:
Arithmetic Operators: used to perform mathematical operations:
- (+) Addition
- (-) Subtraction
- (*) Multiplication
- (/) Division; This gives the result as a float if a float value is used)
- (%) Remainder/Modulus
- (//) Integer Division; This gives the result as an integer if a float value is used)
Conditional Operators: used to compare two conditions:
- (>) Greater than
- (<) Less than
- (>=) Greater than or equal to
- (<=) Less than or equal to
- (==) Equal
Logical Operators: used to compare multiple conditions at the same time:
- (and)
- (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
Top comments (0)