python microbit typeerror_TypeError:无法转换为int - Micropython(TypeError: can't convert to int - Micropy...

TypeError:无法转换为int - Micropython(TypeError: can't convert to int - Micropython)

我有使用micropython的算术问题。

from microbit import *

counter = 0

while True:

display.show('8')

if accelerometer.was_gesture('shake'):

display.clear()

sleep(1000)

counter = counter + 1

display.scroll(counter)

sleep(10)

LED上显示错误:TypeError:无法转换为int

我在这里想念的是什么?

I have arithmetic issues with micropython.

from microbit import *

counter = 0

while True:

display.show('8')

if accelerometer.was_gesture('shake'):

display.clear()

sleep(1000)

counter = counter + 1

display.scroll(counter)

sleep(10)

Error displayed on the LEDs: TypeError: can't convert to int

What am I missing here?

原文:https://stackoverflow.com/questions/43645438

2020-02-25 15:21

满意答案

你有权访问REPL吗? 我会在REPL中自己测试每一行,这样你现在就会出现错误。

或者删除大部分代码,直到你有一些有用的东西,并一次添加一行。 一旦你有错误的行,它将更容易解决。

从这开始:

from microbit import *

counter = 0

while True:

display.show('8')

sleep(10)

Do you have access to the REPL? I would test every line on its own in REPL, this way you will now where the error is.

Alternatively delete most of the code until you have something that works, and add one line at a time. Once you have the line with the error it will be much easier to solve.

Start with this:

from microbit import *

counter = 0

while True:

display.show('8')

sleep(10)

2017-08-02

相关问答

您不能连接一个string与int 。 您将需要使用str函数将int转换为string ,或使用formatting输出。 更改: - print("Ok. Your balance is now at " + balanceAfterStrength + " skill points.")

至: - print("Ok. Your balance is now at {} skill points.".format(balanceAfterStrength))

要么: - print("O...

如果您希望总降雨量是每月数字的总和,只需在整数列表中使用sum()即可。 但是,正如您的错误所示,您有一个字符串列表,您必须明确转换。 有点像 def totalRainfall (rainfall):

return sum([int(x) for x in rainfall])

您的列表是字符串的问题将继续存在问题,所以作为快速修复,我建议您更改此行 rainfall[month] = input ('Please enter the amount for month ' + ...

我在micropython论坛上得到了答案: 你不能。 这是一个TODO项目。 如果要将其放入闪存中,可以将其作为冻结源代码嵌入某些端口。 只需将这些文件放在名为scripts的子目录中,例如esp8266 / scripts或stm32 / scripts。 但它仍将在导入时编译并消耗RAM。 通常,当编码的这种变体仅用于代码的小的,时间关键的部分时,这不应该受到伤害。 I got the answer from someone on micropython forum: You cannot....

微博:bit论坛的回复是 MicroPython micro:bit API主要用于学龄儿童的教学和使用,并且决定不在API中包含回调,因为它们可能导致复杂的错误。 相反,您需要轮询引脚。 The reply from the micro:bit forum is The MicroPython micro:bit API was designed primarily for teaching and use by school children, and it was decided not t...

print("Enter "+int(n)+" Elements")

TypeError: Can't convert 'int' object to str implicitly

你看到错误吗? 尝试这个: print("Enter "+str(n)+" Elements")

print("Enter "+int(n)+" Elements")

TypeError: Can't convert 'int' object to str implicitly

Do you se...

在你的代码中,都没有 if isinstance(row[8], float):

row[8] = float(row[8])

if isinstance(row[8], int):

row[8] = int(row[8])

将执行,因为row[8]是string类型。 你需要做的是简单地将它改为row[8] = float(row[8]) ,它就可以了。 In your code, neither of if isinstance(row...

在类别“ 正是它在锡上说的 ” 更改 x=str("index is"+index+s1marks+s2marks)

成 x = "index is" + str(index) + s1marks + s2marks

但这不是我要做的唯一改变: 您将整数0分配给s1marks和s2marks变量,然后通过input()分配string 。 您还可以显式地将input()转换为str() ,而输入根据定义已经是字符串。 在写入文件file.write(x) ,您还会获取另一个index ,但是您...

你有权访问REPL吗? 我会在REPL中自己测试每一行,这样你现在就会出现错误。 或者删除大部分代码,直到你有一些有用的东西,并一次添加一行。 一旦你有错误的行,它将更容易解决。 从这开始: from microbit import *

counter = 0

while True:

display.show('8')

sleep(10)

Do you have access to the REPL? I would test every line on its own in...

你不是从int(current)整数表示int(current)保存返回值。 尝试 current = int(current)

这应该做到这一点。 You're not saving the return value from int(current), which is the integer representation. Try current = int(current)

That should do it.

如果ctext等于32,则将其转换为string ,当for循环耗尽时,正在执行您正在尝试运行的else作用域: ctext += key1[k] # ctext is a string, key1[k] is an int

与...一样: # Python 3

variable = '2'

variable += 1

>> TypeError: Can't convert 'int' object to str implicitly

In case ctext equals to 32...

相关文章

static int fromByteArray(byte[] bytes)返回int值

在以前使用Hadoop的时候因为mahout里面很多都要求输入文件时序列文件,所以涉及到把文本文件转换

...

小弟今年刚毕业,上了一个星期班,老大要我用jtapi写一个监控程序,弄了两天了,头很大啊。 有一部座

...

webservice可不可以实现动态的返回类型 例如: <T> List<T&g

...

http://halfhalf.posterous.com/dont-work-be-hated-lo

...

转自:http://gaslight.co/blog/how-to-succeed-in-open-s

...

ImageIO.write(image, "jpeg", response.getOutputStre

...

查询方法如下: public List<T> find(String hql, Obje

...

import java.lang.reflect.ParameterizedType;import j

...

最新问答

如果启用了复制处理程序,请确保将其置于其中一个安全角色之后。 我见过人们做的另一件事是在不同的端口上运行admin。 最好在需要auth的页面上使用SSL,这样你就不会发送明确的密码,因此管理和复制将发生在8443上,而常规查询将在8080上发生。 如果您要签署自己的证书,请查看此有用的SO页面: 如何在特定连接上使用不同的证书? I didn't know that /admin was the context for SOLR admin because /admin does not re

第一:在您的样本中,您有: 但是你在询问 //td[@class=‘CarMiniProfile-TableHeader’] (注意TableHeader中的大写'T')。 xpath区分大小写。 第二:通过查询// td [@ class ='CarMiniProfile-TableHeader'] / td,你暗示你在外部td中有一个'td'元素,而它们是兄弟姐妹。 有很多方法可以在这里获得制作和模型

这是你的答案: http://jsfiddle.net/gPsdk/40/ .preloader-container { position: absolute; top: 0px; right: 0px; bottom: 0px; left: 0px; background: #FFFFFF; z-index: 5; opacity: 1; -webkit-transition: all 500ms ease-out;

问题是,在启用Outlook库引用的情况下, olMailItem是一个保留常量,我认为当您将Dim olMailItem as Outlook.MailItem ,这不是问题,但是尝试设置变量会导致问题。 以下是完整的解释: 您已将olMailItem声明为对象变量。 在赋值语句的右侧,在将其值设置为对象的实例之前,您将引用此Object 。 这基本上是一个递归错误,因为你有对象试图自己分配自己。 还有另一个潜在的错误,如果之前已经分配了olMailItem ,这个语句会引发另一个错误(可能是

我建议使用wireshark http://www.wireshark.org/通过记录(“捕获”)设备可以看到的网络流量副本来“监听”网络上发生的对话。 当您开始捕获时,数据量似乎过大,但如果您能够发现任何看起来像您的SOAP消息的片段(应该很容易发现),那么您可以通过右键单击并选择来快速过滤到该对话'关注TCP Stream'。 然后,您可以在弹出窗口中查看您编写的SOAP服务与Silverlight客户端之间的整个对话。 如果一切正常,请关闭弹出窗口。 作为一个额外的好处,wireshar

Android默认情况下不提供TextView的合理结果。 您可以使用以下库并实现适当的aligntment。 https://github.com/navabi/JustifiedTextView Android Does not provide Justified aligntment of TextView By default. You can use following library and achieve proper aligntment. https://github.com/

你的代码适合我: class apples { public static void main(String args[]) { System.out.println("Hello World!"); } } 我将它下载到c:\ temp \ apples.java。 以下是我编译和运行的方式: C:\temp>javac -cp . apples.java C:\temp>dir apples Volume in drive C is HP_PAV

12个十六进制数字(带前导0x)表示48位。 那是256 TB的虚拟地址空间。 在AMD64上阅读wiki(我假设你在上面,对吗?)架构http://en.wikipedia.org/wiki/X86-64 12 hex digits (with leading 0x) mean 48 bits. That is 256 TB of virtual address space. Read wiki on AMD64 (I assume that you are on it, right?) ar

这将取决于你想要的。 对象有两种属性:类属性和实例属性。 类属性 类属性对于类的每个实例都是相同的对象。 class MyClass: class_attribute = [] 这里已经为类定义了MyClass.class_attribute ,您可以使用它。 如果您创建MyClass实例,则每个实例都可以访问相同的class_attribute 。 实例属性 instance属性仅在创建实例时可用,并且对于类的每个实例都是唯一的。 您只能在实例上使用它们。 在方法__init__中定

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值