Basic Arithmetic Operations(Python Solution)

Basic Arithmetic Operations(Python Solution)

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:

  • Multiplication(*): a * b
  • Division(/): a / b
  • Modulus(%): a % b
  • Floor division(//): a // b

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.

要查看或添加评论,请登录

Ebubechukwu O.的更多文章

  • The Growth Marketing Carnot Cycle: A Blueprint for Efficient and Sustainable Growth

    The Growth Marketing Carnot Cycle: A Blueprint for Efficient and Sustainable Growth

    Growth marketing, characterized by data-driven strategies, creative experimentation, and continuous optimization, can…

  • Highly Divisible Triangular Number

    Highly Divisible Triangular Number

    Coding Challenge Level: Beginner Today's challenge requires you to write code to find the Highly Divisible Triangular…

  • Largest Product in a Grid

    Largest Product in a Grid

    Coding Challenge Level: Beginner Today's challenge requires you to write code to find the Largest product of numbers in…

    1 条评论
  • Summation of Primes

    Summation of Primes

    Coding Challenge Level: Beginner Today's challenge requires you to write code to solve for the summation of prime…

  • Special Pythagorean Triplet

    Special Pythagorean Triplet

    Coding Challenge Level: Beginner Todays challenge requires you to write code to find a special Pythagorean triplet. A…

  • Largest Product in a Series

    Largest Product in a Series

    Coding Challenge Level: Beginner Today's challenge requires you to write code to find the largest product in a series…

  • Nth Prime Number

    Nth Prime Number

    Coding Challenge Level: Beginner Today's challenge requires you to write code to find the nth prime number of any given…

  • Sum square difference

    Sum square difference

    Coding Challenge Level: Beginner Today's challenge requires you to write code to find the sum of the squares of the…

  • Smallest Multiple

    Smallest Multiple

    Coding Challenge Level: Beginner Today's challenge requires you to write code to create a python code to solve 2520 is…

  • Largest palindrome product

    Largest palindrome product

    Coding Challenge Level: Beginner Today's challenge requires you to write code to solve for the largest palindrome…

社区洞察

其他会员也浏览了