top of page

Python (8)

  • Writer: Harmony Pang
    Harmony Pang
  • Sep 24, 2023
  • 1 min read

Updated: Oct 11, 2023





1. Binary


def binarySum(self, a, b):
        x,y = int(a,2) , int(b,2)
        return str(bin(x+y)[2:])


int(a, 2) means converting the binary string a into integer by base 2.


bin() converts the integer back to binary number.




2. Square Root


import math
def squareRoot(self, x):
    return int(sqrt(x))


sqrt() returns the square root of a number.


It returns a float number with decimal.












Thank you for completing this tutorial!


See you in Python (9).









© 2023 Harmony Pang. All rights reserved.








Commentaires


Drop Me a Line, Let Me Know What You Think

Thanks for submitting!

© 2023 by Harmony Pang. All rights reserved.

bottom of page