用python完成计算一个图形中三角形数目
用python完成计算一个图形中三角形数目,微信朋友圈的一个游戏,数三角形的数目。自己用Python了一个小程序来处理了一下,简介写在了这儿。
1. [文件] triangle_counter.py ~ 2KB
#!/usr/bin/python """ --------------------------------------------------------------------------------------------------- 2015.07.23 Grey www.iplaypy.com *************************************************************************************************** Counter all the triangles in a picture --------------------------------------------------------------------------------------------------- """ import itertools,string def CounterTriangle(): print "All the triangles we can find in the picture are as follows:" triangle_number = 0 sides_match_list = ['abh','acgi','adfj','aek','bcde','efgh','hijk'] dot_list = [] i = 0 while i < 26: dot_list.append(string.lowercase[i]) if string.lowercase[i] == 'k': break else: i += 1 for each_combination in itertools.combinations(dot_list,3): triangle_flag = True for each_dot_combination in itertools.combinations(each_combination,2): for each_side in sides_match_list: if each_dot_combination[0] in each_side and each_dot_combination[1] in each_side: triangle_flag = True break else: triangle_flag = False else: triangle_flag = False break line_flag = False for each_side in sides_match_list: if each_combination[0] in each_side and each_combination[1] in each_side and each_combination[2] in each_side: line_flag = True if triangle_flag == True and line_flag == False: triangle_number += 1 print "%d : %s" % (triangle_number,each_combination) print "The number of triangles in the picture is : %d" % triangle_number CounterTriangle()
2. [图片] triangle.jpg

玩蛇网文章,转载请注明出处和文章网址:https://www.iplaypy.com/code/graphics/gr341.html
相关文章 Recommend
- • 2019年3月最新消息: Python 3.4.10 现已推出
- • [上海]招Python量化系统开发工程师
- • 支付宝官方给力福利!每天可领1个红包,直接当
- • 优集品网络科技有限公司招Python中/高级工程师
- • 爱因互动科技发展有限公司招募Python开发攻城狮
- • mozio招聘Python/Django工程师
- • Kavout金融科技公司招Python研发工程师
- • Python数组逆向输出,编程练习题实例四十
- • Python数组插入排序,编程练习题实例三十九
- • Python矩阵for循环应用,编程练习题实例三十八
- • Python操作Redis数据库方面的问题
- • 请python高手帮我看看这段python代码中函数setter的
我要分享到:
上一篇:没有了
下一篇:python3代码完成抓取某论坛贴图教程
下一篇:python3代码完成抓取某论坛贴图教程
必知PYTHON教程 Must Know PYTHON Tutorials
- • python 解释器
- • python idle
- • python dir函数
- • python 数据类型
- • python type函数
- • python 字符串
- • python 整型数字
- • python 列表
- • python 元组
- • python 字典
- • python 集合
- • python 变量
- • python print
- • python 函数
- • python 类定义
- • python import
- • python help
- • python open
- • python 异常处理
- • python 注释
- • python continue
- • python pass
- • python return
- • python global
- • python assert
- • python if语句
- • python break
- • python for循环
- • python while循环
- • python else/elif
- • lambda匿名函数
必知PYTHON模块 Must Know PYTHON Modules
- • os 模块
- • sys 模块
- • re 正则表达式
- • time 日期时间
- • pickle 持久化
- • random 随机
- • csv 模块
- • logging 日志
- • socket网络通信
- • json模块
- • urlparse 解析URL
- • urllib 模块
- • urllib2 模块
- • robotparser 解析
- • Cookie 模块
- • smtplib 邮件
- • Base64 编码
- • xmlrpclib客户端
- • string 文本
- • Queue 线程安全
- • math数学计算
- • linecache缓存
- • threading多线程
- • sqlite3数据库
- • gzip压缩解压
最新内容 NEWS
- • Python用来处理图像几何变换
- • python实现jpg图片文字转成pdf格式
- • python3代码完成抓取某论坛贴图教程
- • 用python完成计算一个图形中三角形数目
- • Python jpg图片裁剪处理源码
- • Python数学方程式画心型图案源码示例
- • 判断并修改图片分辨率的python方法
- • PyQt制作支持拖动缩放小时钟
- • Python工程图绘制编程函数基本应用源码
- • 可视化SVM分类器开源实现的python代码
图文精华 RECOMMEND
-
python实现jpg图片文字转成pdf格式
-
用python完成计算一个图形中三角形
-
Python数学方程式画心型图案源码示
-
PyQt制作支持拖动缩放小时钟
-
可视化SVM分类器开源实现的pytho
-
Python爬虫与K-means聚类算法分析多
热点文章 HOT
- Python用来处理图像几何变换
- PyQt制作支持拖动缩放小时钟
- Python数学方程式画心型图案源码示例
- 可视化SVM分类器开源实现的python代码
- Python爬虫与K-means聚类算法分析多数据图片
- Python jpg图片裁剪处理源码
- Python工程图绘制编程函数基本应用源码
- Python调用摄像头摄像并保存图片的方法源