+ 2

What's wrong with the syntax?

File "loading.py", line 13 print(hl + " Progress:[" + str(perc) + "%]"+ normal + "[" + progress + empty + "]", end="\r") ^ SyntaxError: invalid syntax What is it with the syntax that is wrong? The variables is defined earlier in the whole script so never mind the variables.

24th May 2018, 5:31 PM
Hampus Mathiesen
Hampus Mathiesen - avatar
6 Respostas
+ 2
Gotcha. Found your problem for you. CHANGE: perc = int(float(per) * 100 TO: perc = int(float(per)) * 100 Sometimes Python will generate the error on the line where it gets stuck, but the problem is sometimes just coming from the line prior. In this case, you just forgot your closing parenthesis.
24th May 2018, 6:05 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
Hard to say since you didn't provide your code. Maybe put "" + hl at the beginning so it realizes that it's a string instead of a calculation. I'm no Python expert, so test it and let me know. If you can post link to your code, I can tell you with 100% certainty.
24th May 2018, 5:47 PM
Fata1 Err0r
Fata1 Err0r - avatar
+ 1
import time normal = "\033[0m" hl = "\33[102m" for x in range(11): progress = "=" * x em = 11 - len(progress) - 1 empty = " " * em per = "0." + str(x) perc = int(float(per) * 100 print(hl + " Progress:[" + str(perc) + "%]"+ normal + "[" + progress + empty + "]", end="\r") time.sleep(1) print(" ")
24th May 2018, 5:58 PM
Hampus Mathiesen
Hampus Mathiesen - avatar
+ 1
It doesn't work in sololearn so you'll have to use the IDE.
24th May 2018, 5:59 PM
Hampus Mathiesen
Hampus Mathiesen - avatar
+ 1
the line before print misses a ) at the end. Could that be the problem? https://code.sololearn.com/cS2n91O4sPS5/?ref=app
24th May 2018, 6:03 PM
davy hermans
davy hermans - avatar
+ 1
Thanks!
24th May 2018, 6:40 PM
Hampus Mathiesen
Hampus Mathiesen - avatar