Input: 13
Output: def to_binary(num):
result = “”
while num > 0:
remainder = num % 2
num = num // 2
result = str(remainder) + result
return result
print(to_binary(13)) # ‘1101’
Prompt: Below is an instruction that describes a task. Write a response that appropriately completes the request.
### Instruction:
Create a Python function that converts an integer into a binary representation as a string.
### Input:
13
### Output:
def to_binary(num):
result = “”
while num > 0:
remainder = num % 2
num = num // 2
result = str(remainder) + result
return result
print(to_binary(13)) # ‘1101’