Skip to content

Changing Name of file and adding doctests in file. #9504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DIRECTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@
* [Basic Maths](maths/basic_maths.py)
* [Binary Exp Mod](maths/binary_exp_mod.py)
* [Binary Exponentiation](maths/binary_exponentiation.py)
* [Binary Exponentiation 2](maths/binary_exponentiation_2.py)
* [Binary Exponentiation 2](maths/binary_multiplication.py)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't modify DIRECTORY.md. This file is auto-generated with a script.

* [Binary Exponentiation 3](maths/binary_exponentiation_3.py)
* [Binomial Coefficient](maths/binomial_coefficient.py)
* [Binomial Distribution](maths/binomial_distribution.py)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@


def b_expo(a: int, b: int) -> int:
"""
Calculate the result of multiplying 'a' and 'b' using bitwise multiplication.
Parameters:
a (int): The first number.
b (int): The second number.
Returns:
int: The result of 'a' multiplied by 'b'.
Examples:
>>> b_expo(2, 3)
6
>>> b_expo(5, 0)
0
>>> b_expo(3, 4)
12
>>> b_expo(10, 5)
50
>>> b_expo(0, 5)
0
>>> b_expo(2, 1)
2
>>> b_expo(1, 10)
10
"""
res = 0
while b > 0:
if b & 1:
Expand All @@ -23,6 +46,12 @@ def b_expo(a: int, b: int) -> int:
return res


if __name__ == "__main__":
import doctest

doctest.testmod()
Comment on lines +49 to +52
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main block should be placed at the bottom of the file.



def b_expo_mod(a: int, b: int, c: int) -> int:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function also needs doctests

res = 0
while b > 0:
Expand Down