+ 7

Can you plz tell me what's wrong with this code? ↓ in Python

#It is showing SyntaxError! def table(x):     i=1     while (i<=10):         print(x, "×", i, "=", i*x)         i += 1     print( "_"*28, "\n") table(5)

12th May 2020, 9:58 AM
Aayush-droid
Aayush-droid - avatar
3 Respostas
+ 4
There is an issue with some spaces that are used for indentation. To name the line of 'while ...' uses ascii char 160 3 times, where this character is a so called non-breaking space plus one regular space (ascii 32). (160, 160, 160, 32, 119, 104, 105, 108, 101, ) Characters like ascii 160 can not be processed from the parser of python. If you remove all spaces on left side of the code, and put them in again from keyboard, the code will run. Things like this can happen when copying and pasting from the web or from text processing systems like word.
12th May 2020, 10:40 AM
Lothar
Lothar - avatar
+ 1
Hi! line " while (i<=10): " does not need parenthesis. For some reason, i gives me an error, so I have changed it's name to 'count'. Hope this helps! def table(x): count = 1 while count <= 10: print(x, "×", count, "=", (x*count)) count += 1 table(5)
12th May 2020, 10:21 AM
Teeny Sanguini
Teeny Sanguini - avatar
+ 1
PHP code goes here ?>
13th May 2020, 4:11 AM
Dahi Mohamed
Dahi Mohamed - avatar