python 变量不接受名称
我试图在一个非常基本的碰撞检测程序中声明一些简单的变量作为函数的一部分。 由于某种原因,它拒绝我的变量(尽管只有其中一些变量,即使它们几乎相同)。 这是该函数的代码;
def TimeCheck():
timechecknumber = int(time.time())
timecheckdiv = backcolourcheck % 5
if timecheckdiv < 1:
timecheck = true
else:
timecheck = false
if timecheck == true:
backgroundr = (int(random.random()*255)+1
backgroundg = (int(random.random()*255)+1
backgroundb = (int(random.random()*255)+1
由于某种原因它接受backgroundr但不接受backgroundg,有人知道为什么吗? 谢谢
I'm trying to declare a few simple variables as part of a function in a very basic collision detection programme. For some reason it's rejecting my variables (although only some of them even though they're near identical). Here's the code for the function;
def TimeCheck():
timechecknumber = int(time.time())
timecheckdiv = backcolourcheck % 5
if timecheckdiv < 1:
timecheck = true
else:
timecheck = false
if timecheck == true:
backgroundr = (int(random.random()*255)+1
backgroundg = (int(random.random()*255)+1
backgroundb = (int(random.random()*255)+1
for some reason it accepts backgroundr but not backgroundg, anyone got any ideas why? thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
以
backgroundr
开头的行中的括号不匹配。 我想也许你想要这个:请注意,接下来的两行也有不匹配的括号,所以你也必须修复这些。
You have mismatched parentheses on the line beginning with
backgroundr
. I think maybe you want this:Note that each of the next two lines also have mismatched parentheses, so you'll have to fix those, too.
mipadi 的答案总是会产生 1。在转换为 int 之前,您需要乘以 255。 尝试这个。
mipadi's answer will always yield a 1. You need to multiply by 255 before you cast to int. Try this.