TypeError: unsupported types for : 'int', 'NoneType' in Python
TypeError: unsupported types for : 'int', 'NoneType' in Python
我正在为客户端编写一个程序,该程序通过客户端记录的内置平均值无线电从服务器接收平均值字符串。我收到一个 TypeError 消息:"unsupported types for : 'int', 'NoneType'".
这是我的代码:
from microbit import *
import radio
radio.on()
blink = Image("99999:"
"99999:"
"99999:"
"99999:"
"99999")
radio.send("power on")
while True:
incoming = radio.receive()
if incoming is not None:
incoming = float(incoming)
sleep(500 - running_time() % 500)
acceleration = accelerometer.get_z()
radio.send(str(acceleration))
acceleration = float(acceleration)
if acceleration > 2 * incoming or acceleration < .5 * incoming:
display.show(blink)
microbit.sleep(150)
display.clear()
microbit.sleep(150)
错误发生在这一行:
if acceleration > 2 * incoming or acceleration < .5 * incoming:
试试这个:
from microbit import *
import radio
radio.on()
blink = Image("99999:"
"99999:"
"99999:"
"99999:"
"99999")
radio.send("power on")
while True:
incoming = radio.receive()
if incoming is not None:
incoming = float(incoming)
sleep(500 - running_time() % 500)
acceleration = accelerometer.get_z()
radio.send(str(acceleration))
acceleration = float(acceleration)
if acceleration > 2 * incoming or acceleration < .5 * incoming:
display.show(blink)
microbit.sleep(150)
display.clear()
microbit.sleep(150)
基本原理: 您的代码(已发布)执行第一个 if
以检查 incoming
是否为 None
。但是,您在之前的缩进级别有以下代码块,因此,当 incoming
为 None
.
时,这些代码块也会执行
我正在为客户端编写一个程序,该程序通过客户端记录的内置平均值无线电从服务器接收平均值字符串。我收到一个 TypeError 消息:"unsupported types for : 'int', 'NoneType'".
这是我的代码:
from microbit import *
import radio
radio.on()
blink = Image("99999:"
"99999:"
"99999:"
"99999:"
"99999")
radio.send("power on")
while True:
incoming = radio.receive()
if incoming is not None:
incoming = float(incoming)
sleep(500 - running_time() % 500)
acceleration = accelerometer.get_z()
radio.send(str(acceleration))
acceleration = float(acceleration)
if acceleration > 2 * incoming or acceleration < .5 * incoming:
display.show(blink)
microbit.sleep(150)
display.clear()
microbit.sleep(150)
错误发生在这一行:
if acceleration > 2 * incoming or acceleration < .5 * incoming:
试试这个:
from microbit import *
import radio
radio.on()
blink = Image("99999:"
"99999:"
"99999:"
"99999:"
"99999")
radio.send("power on")
while True:
incoming = radio.receive()
if incoming is not None:
incoming = float(incoming)
sleep(500 - running_time() % 500)
acceleration = accelerometer.get_z()
radio.send(str(acceleration))
acceleration = float(acceleration)
if acceleration > 2 * incoming or acceleration < .5 * incoming:
display.show(blink)
microbit.sleep(150)
display.clear()
microbit.sleep(150)
基本原理: 您的代码(已发布)执行第一个 if
以检查 incoming
是否为 None
。但是,您在之前的缩进级别有以下代码块,因此,当 incoming
为 None
.