Beginner in Python, can't get this for loop to stop -


bit_128 = 0 bit_64 = 0 bit_32 = 0 bit_64 = 0 bit_32 = 0 bit_16 = 0 bit_8 = 0 bit_4 = 0 bit_2 = 0 bit_1 = 0   number = int(input("enter number converted: "))  power in range(7,0,-1):  if (2**power) <= number: place_value = 2**power if place_value == 128:     bit_128 = 1 elif place_value == 64:     bit_64 = 1 elif place_value == 32:     bit_32 = 1 elif place_value == 16:     bit_16 = 1 elif place_value == 8:     bit_8 = 1 elif place_value == 4:     bit_4 = 1 elif place_value == 2:     bit_2 = 1 elif place_value ==1:        bit_1 = 1 number = number - (place_value) if number == 0:        print ("binary form of"),number,("is"),bit_128,bit_64,bit_32,bit_16,bit_8,bit_4,bit_2,bit_1 

i want loop move next 'power' value when fails first if condition, when run in interpreter, program keeps on running despite first condition not being true. want move on next conditions if first condition turns out true. how can this? first "big" program in python, , i'm having hard time figuring out. tips appreciated. btw, program meant convert number 1-255 binary form.

if want loop go next value, need use continue keyword:

... power in range(7,0,-1):     if (2**power) <= number:         place_value = 2**power         continue     ... 

Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -