def check_mx_range1(mx, my):
switch1 = 0
while switch1==0:
for mx_range1 in mousedata.mx_ranges1:
if mx_range1[0] < mx < mx_range1[1] and 890 < my < 920 and switch1==0:
switch1+=1
a11=0
b11=0
a11=str(mx_range1[2])
b11=str(mx_range1[3])
mousedata.dic_n[a11]+=1
print(mx_range1)
print(a11)
print(b11)
print(mousedata.dic_n[a11])
return True
if False:
break
return False
可能很难说清楚……好吧,我正在制作” drunkopoly”,因此这些函数调用范围数组并将其放入字典中.
字典如下:
dic_s={‘101’: [868.0, 905.0], ‘102’: [827.0, 905.0], ‘103’: [785.0, 905.0], ‘104’: [743.0, 905.0], ‘105’: [701.0, 905.0], ‘106’: [659.0, 905.0], ‘107’: [617.0, 905.0], ‘108’: [575.0, 905.0], ‘109’: [533.0, 905.0], ‘110’: [491.0, 905.0], ‘111’: [449.0, 905.0], ‘112’: [407.0, 905.0], ‘113’: [365.0, 905.0], ‘114’: [323.0, 905.0], ‘115’: [281.0, 905.0], ‘116’: [239.0, 905.0], ‘117’: [197.0, 905.0], ‘118’: [155.0, 905.0]}
dic_n={‘1’: 0, ‘2’: 0, ‘3’: 0, ‘4’: 0, ‘5’: 0, ‘6’: 0, ‘7’: 0, ‘8’: 0, ‘9’: 0, ’10’: 0, ’11’: 0, ’12’: 0, ’13’: 0, ’14’: 0, ’15’: 0, ’16’: 0, ’17’: 0, ’18’: 0, ’19’: 0, ’20’: 0, ’21’: 0, ’22’: 0, ’23’: 0, ’24’: 0, ’25’: 0, ’26’: 0, ’27’: 0, ’28’: 0, ’29’: 0, ’30’: 0, ’31’: 0, ’32’: 0, ’33’: 0, ’34’: 0, ’35’: 0, ’36’: 0, ’37’: 0, ’38’: 0, ’39’: 0, ’40’: 0, ’41’: 0, ’42’: 0, ’43’: 0, ’44’: 0, ’45’: 0, ’46’: 0, ’47’: 0, ’48’: 0, ’49’: 0, ’50’: 0, ’51’: 0, ’52’: 0, ’53’: 0, ’54’: 0, ’55’: 0, ’56’: 0, ’57’: 0, ’58’: 0, ’59’: 0, ’60’: 0, ’61’: 0, ’62’: 0, ’63’: 0, ’64’: 0, ’65’: 0, ’66’: 0, ’67’: 0, ’68’: 0, ’69’: 0, ’70’: 0, ’71’: 0, ’72’: 0}
dic_s涉及18个曲面的位置,尽管它实际上应该为72,而dic_n涉及单击该区域的次数.
现在,运行数字计数器的主要代码是:
def run_game():
pygame.init()
Font information
gamefont=pygame.freetype.Font(“OpenSans-Bold.ttf”,12)
Number in font mx and my posion of mouse curser
gamestage=0
n=0
text_surface, rect = gamefont.render(“0”,(4, 8, 18))
text_surface1, rect = gamefont.render(“0”,(4, 8, 18))
Main screen display options
ai_settings = Settings()
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
pygame.display.set_caption(“Drunkopoly”)
b=screen.blit(board,(0,0))
Beggining of the main game loop
while True:
keyboard and mouse events
for event in pygame.event.get():
if event.type == pygame.QUIT:
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:
if gamestage == 0 and gamestage
Original: https://blog.csdn.net/weixin_42336892/article/details/113648866
Author: 张大神气
Title: python中blit的意思_python-如何有效地blit 72图像
相关阅读
Title: Python 报错 ValueError list.remove(x) x not in list 解决办法
平时开发 Python 代码过程中,经常会遇到这个报错:
ValueError: list.remove(x): x not in list
错误消息也很清楚,删除的元素不在列表中。
[En]
The error message is also clear that the removed element is not in the list.
比如:
>>> lst = [1, 2, 3]
>>> lst.remove(4)
Traceback (most recent call last):
File "", line 1, in <module>
ValueError: list.remove(x): x not in list
但还有一种情况也会引发这个错误,就是在循环中使用 remove
方法。
举一个例子:
>>> lst = [1, 2, 3]
>>> for i in lst:
... print(i, lst)
... lst.remove(i)
...
1 [1, 2, 3]
3 [2, 3]
>>>
>>> lst
[2]
产量与我们的预期不符。
[En]
The output is not consistent with our expectations.
如果这是一个双重循环呢?事情会变得更加复杂。让我们看另一个例子:
[En]
What if it’s a double loop? It’s gonna be a little more complicated. Let’s look at another example:
>>> lst = [1, 2, 3]
>>> for i in lst:
... for a in lst:
... print(i, a, lst)
... lst.remove(i)
...
1 1 [1, 2, 3]
1 3 [2, 3]
Traceback (most recent call last):
File "", line 4, in <module>
ValueError: list.remove(x): x not in list
这样一来,输出就更乱了,错误就报出来了。
[En]
In this way, the output is even more chaotic, and the error is reported.
那怎么 解决呢?办法也很简单,就是在每次循环的时候使用列表的拷贝。
看一下修正之后的代码:
>>> lst = [1, 2, 3]
>>> for i in lst[:]:
... for i in lst[:]:
... print(i, lst)
... lst.remove(i)
...
1 [1, 2, 3]
2 [2, 3]
3 [3]
这样的话就没问题了。
以上就是本文的全部内容,如果你觉得不错,环境点赞、转发、跟随,谢谢你的支持。
[En]
The above is the whole content of this article, if you think it is good, the environment * like * , * forward * and * follow * , thank you for your support.
推荐阅读:
- 计算机经典书籍
- 技术博客 : 硬核后端开发技术干货,内容包括 Python、Django、Docker、Go、Redis、ElasticSearch、Kafka、Linux 等。
- Go 程序员 : Go 学习路线图,包括基础专栏,进阶专栏,源码阅读,实战开发,面试刷题,必读书单等一系列资源。
- 面试题汇总 : 包括 Python、Go、Redis、MySQL、Kafka、数据结构、算法、编程、网络等各种常考题。
Original: https://blog.csdn.net/zyx6a/article/details/124159114
Author: yongxinz
Title: Python 报错 ValueError list.remove(x) x not in list 解决办法
原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/343159/
转载文章受原作者版权保护。转载请注明原作者出处!