+ 2
Why will my program not store bit? Solved
def Bit(x): bit = [] if x == 1: bit.append(1) return bit elif x == 0: bit.append(0) return bit else: while x > 0: n = x % 2 bit.insert(0,n) x = x / 2 return bit Bit(1) print(bit)
5 odpowiedzi
+ 3
You defined the bit variable inside of the Bit function. That's why you can't access it from outside. But since you return it from the function, you can assign it to a new variable.
If you do:
bit = Bit(1)
print(bit)
You're assigning the result of the Bit function call to a new variable called bit, and printing that.
+ 2
thanks that was really helpful. : )
+ 1
You did not assign the result of the Bit function call to a variable. Try bit = Bit(1)
+ 1
oh thank you but how am I suppose to store the bit if it is not a integer
+ 1
wait why bit = Bit 1