0

I am writing a program for a client that receives a string of an average from a server through the built in radio of averages which the client records. I get a ValueError saying "invalid syntax for integer with base 10" in a line where I attempt to convert a string saved into a variable into an integer. I was able to do this with no errors in a line above the line with an error.

my code is below:

from microbit import *
import radio

radio.on()

blink = Image("99999:"
              "99999:"
              "99999:"
              "99999:"
              "99999")

radio.send("power on")

while True:
    sleep(50 - running_time() % 50)
    acceleration = accelerometer.get_z()
    acceleration = int(acceleration)
    radio.send(str(acceleration))

    incoming = radio.receive()
    if incoming is not None:
        incoming = int(incoming)

    while acceleration > (2 * incoming) or acceleration < (.5 * incoming):
        display.show(blink)
        sleep(300)
        display.clear()
        sleep(300)

the line with the error is

incoming = int(incoming)
6
  • 1
    Not all strings can be converted to integer Commented Jan 31, 2017 at 19:48
  • It could be sent with a character, probably if the number has commas to separate hundreds and thousands. Try doing str.replace() by removing commas and trying. It might work. Commented Jan 31, 2017 at 19:51
  • Can you provide the entire stack trace? it will tell you what the string was that failed. Commented Jan 31, 2017 at 19:59
  • the string that would have been sent would be "3.5" Commented Jan 31, 2017 at 20:06
  • 1
    Thanks. I just changed it to float(incoming) and no more error! Commented Jan 31, 2017 at 20:13

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.