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.
Comments