Jun-25-2018, 03:51 PM
So I'm a quite new python programmer and I'm now working on a digital binary clock (it should convert the hour and minute in binary numbers).
I was trying to add some 0's in front of the binary outputs with a length less than 5 for the hours (because 24, i.e. the greatest number, is 11000 in binary; I wanted to have a constant length of the outputs). The problem is that Python recognises the first thing (symbol, variable, ect.) after "for i in range(5-len(timem)" as a syntax error (whatever I do: if I delete the ":" or everything after "for i in range(5-len(timem)") in:
I was trying to add some 0's in front of the binary outputs with a length less than 5 for the hours (because 24, i.e. the greatest number, is 11000 in binary; I wanted to have a constant length of the outputs). The problem is that Python recognises the first thing (symbol, variable, ect.) after "for i in range(5-len(timem)" as a syntax error (whatever I do: if I delete the ":" or everything after "for i in range(5-len(timem)") in:
while True: timeh = "{0:b}".format((int(time.ctime()[11:13])) for i in range(5-len(timeh)): timeh = "0" + timeh timem = "{0:b}".format((int(time.ctime()[14:16])) for i in range(5-len(timem)): timem = "0" + timem print(timeh + " " + timem)Could anyone help me please (in a way or in another)?