Basic Arithmetic Operations(Python Solution)
Ebubechukwu O.
Founder and Technology at Tutlee | AI/ML Enthusiast | Passionate About Technical Education & Sustainable Impact
Coding Challenge Level: Beginner.
Yesterday in the Booka Technika newsletter, we built a band name generator and previously we had looked at solving for odd numbers in a list of numbers.
Today's coding challenge would be to execute basic arithmetic operations.
Python language supports several types of operators. If you would like to learn all about operators in python, refer to the subject on w3schools.
For this exercise, you will be using the following arithmetic operators:
Exercise:
Write a function that multiplies two integer variables f and g, divides the product by two and outputs the remainder with respect to division by 7.
Solution Algorithm:
Solving this would directly follow the following order:
def soln(f, g)
return f * g // 2 % 7
The floor operator returns an integer. Knowing this allows for an alternate solution to the problem where type conversion turns the result from float to integer. Another way to do this without the floor operator is demonstrated like this:
def soln(f, g):
return int(f * g / 2) % 7
If you would like to run this solution in real time, please check here.
Thank you for reading this far. Please share in the comment, how you would solve this challenge in your own way. You can include any programming language you are familiar with. Someone might benefit from you.