Page 1 of 1

Code syntax error

Posted: Tue Jan 31, 2017 8:08 pm
by Backintime
Hello everyone,

I'm working on a pedometer feature for my micro:bit and I'm trying to upload the following code below. However, after it's uplodaed, this error message appears:
line 7 syntax error - invalid syntax

I can't find the correct syntax that would make the code work. Could somebody help me on this one? ;) Thanks!

from microbit import *
steps = 0
while True:
#display.clear()
agx = accelerometer.get_x()
if agx > 300:
steps += 1
sleep(100)
if steps > 0:
display.set_pixel(0,0,9)
if steps > 10:
display.set_pixel(1,0,9)
if steps > 20:
display.set_pixel(2,0,9)
if steps > 30:
display.set_pixel(3,0,9)
if steps > 40:
display.set_pixel(4,0,9)
if steps > 50:
display.set_pixel(0,1,9)
if steps > 60:
display.set_pixel(1,1,9)
if steps > 70:
display.set_pixel(2,1,9)
if steps > 80:
display.set_pixel(3,1,9)
if steps > 90:
display.set_pixel(4,1,9)

Re: Code syntax error

Posted: Tue Jan 31, 2017 10:53 pm
by Turbinenreiter

Code: Select all

val = val + 1
short

Code: Select all

val =+ 1
//edit: this is bullshit, ignore it.

Re: Code syntax error

Posted: Tue Jan 31, 2017 11:29 pm
by dhylands
Just being nit picky here, but:

Code: Select all

>>> val = 7
>>> val += 1
>>> val
8
>>> val =+ 1
>>> val
1

Re: Code syntax error

Posted: Wed Feb 01, 2017 12:00 am
by deshipu
Hard to say what is wrong with that code without seeing the indentation...

Re: Code syntax error

Posted: Wed Feb 01, 2017 12:45 pm
by Turbinenreiter
Listen to Dave not me. Don't know what I was thinking.

Re: Code syntax error

Posted: Wed Nov 15, 2017 2:11 am
by rhubarbdog
It's hard to tell without indentation, i think your code reads

Code: Select all

if agx > 300:
steps+=1
But should read

Code: Select all

if agx > 300:
    steps+=1