Homework
Below is an example of decimal number to binary converter which you can use as a starting template.
def find(dec_num): #dec_num is the decimal number
if(dec_num==0):
# this will check if the number inuputed has a remainder or not
return
else:
find(int(dec_num/2))# this is for if the remainder is not 0, so it will divide by 2
print(dec_num % 2, end="") #The % is to calulcate what the remainder is
# We need to make sure to include the end="", because if we dont do this, the numbers will be printed in different lines, but we want them in one single line.
#now we need to call the function dec_num
find(10)
num = 23
# print(bin(num)) now if we just print this we will get something like this as an answer: 0b10111
#So if we want to remove the Ob, we want to add [2:]
print(bin(num)[2:])
num = int(input("Please enter a number!"))
print(bin(num)[2:])
print(ord("A"))
# The ord function converts any character(letter) into an integer, this is case sensative
# we are going to build off of this
# Now if I want this in bianry form, I am going to use the format function
print(format(ord("A"), "b")) # "b" stands for binary
# I am still a little unsure of why the string is needed, but I do know is that if we dont include it, it will not convert it into a binary number
text = "Hi I am going to convert this text into binary"
# So in the following code what I did was first use ord to convert each and every character in the string to an integer, then i used the format function to format it into a binary number
# the " " is the whitespace also the connector
# everything in the collection(whitespace) that we pass to the join() function will be joined together using the string
binary = " ".join(format(ord(c), "b") for c in text) # the for c will go through each and every character in the string and convert it into a binary
print(binary)