createBinKeyFromKeykey return binKey Write a function that

createBinKeyFromKey(key) - return binKey. Write a function that converts your key (which is an integer) to binary format (as a string of 0\'s and 1\'s). The built-in Python function bin takes an integer parameter and converts to a binary string starting with 0b followed by the binary conversion. For example, bin(9) returns \'0b1001\'. Can you think of a way to slice off the first two characters?

Solution

def binkey(n):#function which converts integer to binary
    return bin(n)#which converts integer to a binary form and return as string

l=\"\"+binkey(9)#receving string
s = l[2:]#slicing the string
print(\"String before slicing:\")#printing output
print(l,\"\ \")
print(\"String after slicing:\")
print(s,\"\ \")

output:-

String before slicing:0b1001

String after slicing:1001

createBinKeyFromKey(key) - return binKey. Write a function that converts your key (which is an integer) to binary format (as a string of 0\'s and 1\'s). The bui

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site