I'm not sure what you're asking, could you explain more?
would print 5 to the screen as a and b are integer values.
for me if I do print(a + b) when a = 5 and b = 22 it comes up as 522 and would you know what code to use if I wanted to get any number divided by 2 until the answer reached 0? thanks
for me if I do print(a + b) when a = 5 and b = 22 it comes up as 522 and would you know what code to use if I wanted to get any number divided by 2 until the answer reached 0? thanks
When you initialize a and b are you using quotes like this-
?
The quote marks would make it a string, but should make a an int.
a/b would give a divided by b, but what do you mean by until the answer reaches 0?
but 3+2 is not 195. Ur honestly taking this to new unnecessary levels.
Sorry, you've lost me. The 195 is 97 ('a' in asci) + ('b' in asci). I'm just pointing out that you kinda can add two characters together, though as I say, pointless. Concatenation is essentially the same thing as addition for strings.
When you initialize a and b are you using quotes like this-
?
The quote marks would make it a string, but should make a an int.
a/b would give a divided by b, but what do you mean by until the answer reaches 0?
say you had 122, is there a way to make python code do this: 122/2 = 61 r 0 61/2 = 30 r 1 30/2 = 15 r 0 15/2 = 7 r 1 7/2 = 3 r 1 3/2 = 1 r 1 1/2 = 0 r 1 0/2 = 0 r 0 I'm trying to make code that converts denary to binary, or if there is an easier way to do it then what is it? :/
say you had 122, is there a way to make python code do this: 122/2 = 61 r 0 61/2 = 30 r 1 30/2 = 15 r 0 15/2 = 7 r 1 7/2 = 3 r 1 3/2 = 1 r 1 1/2 = 0 r 1 0/2 = 0 r 0 I'm trying to make code that converts denary to binary, or if there is an easier way to do it then what is it? :/
easiest way is to use recursion
def convertToBinary(n): """Function to print binary number for the input decimal using recursion""" if n > 1: convertToBinary(n//2) print(n % 2,end = '') # decimal number dec = 34 convertToBinary(dec) 100010
def convertToBinary(n): """Function to print binary number for the input decimal using recursion""" if n > 1: convertToBinary(n//2) print(n % 2,end = '' # decimal number dec = 34 convertToBinary(dec) 100010