Homework/Hacks

our homework we have decided for a decimal number to binary converter. You must use conditional statements within your code and have a input box for where the decimal number will go. This will give you a 2.7 out of 3 and you may add anything else to the code to get above a 2.7.

Below is an example of decimal number to binary converter which you can use as a starting template.

num = int(input("What is your decimal number"))
def DecimalToBinary(num):
    strs = ""
    while num:
        # if (num & 1) = 1
        if (num & 1):
            strs += "1"
        # if (num & 1) = 0
        else:
            strs += "0"
        # right shift by 1
        num >>= 1
    return strs
 
# function to reverse the string
def reverse(strs):
    strv = (strs[::-1])
    return strv
 
# Driver Code


print("Binary number for", num, "is: ",reverse(DecimalToBinary(num)))
Binary number for 17 is:  10001