+ 1
why doesnt this work
code =('010010001000100101000') try: x = bin(code).split('b') print(x) if x==SyntaxError: try: x = bin(code) print(x) if x==ValueError: try: code = (1, 0) bin(code) print(x) code.split(0) z = len(code(1)) bin(z) float(code) if z==SyntaxError: code==False else: print(code) it is EOF error on line 29(there is not code on L29) Please explain/solve
3 Antworten
+ 1
Just a few problems:
The first is that the indentation is a little off, and as Python generally relies on indents to declare certain blocks, making sure that everything is properly indented is important.
The second thing is that the exception handling isn't as it is supposed to be. With Python, exceptions are typically handled in try/catch blocks, with the try block running first and the catch block running if any errors occur. In your code, you're trying to catch exceptions as if the exception itself was set as the value of the variable, which it is generally not.
Basically, for the try/catch blocks to work, they would need to look something like this:
try:
#Statement(s)
catch:
#Statement(s) to run if exception is raised in try block
+ 1
Ok thx, I'll try getting that
0
The error is Syntax error: unexpected EOF while parsing