Python脚本09 —— 一个计算题
2015-09-22 13:42
573 查看
#coding=utf-8 # a + b - 9 = 4 # + - - # c - d * e = 4 # / * - # f + g - h = 4 # = = = # 4 4 4 maxNumber = 20 minNumber = 0 for a in xrange(0,13): b = 13 - a # 横着第一个公式得到 a + b = 13 for c in xrange(minNumber,maxNumber): for d in xrange(minNumber,maxNumber): for e in xrange(0,5): for f in xrange(1,maxNumber):# 竖着第一个公式有除法,所以f不能为0. 且为了避免int作除法结果被截断,增加默认公式c == f * (4 - a) for g in xrange(minNumber,maxNumber): h = 5 - e #竖着最后一个公式得到 e + h = 5 if (a + b - 9 == 4) and (c - d * e == 4) and (f + g - h == 4) and (a + c / f == 4) and (c == f * (4 - a)) and (b - d * g == 4) and (9 - e - h == 4): print str(a) + ' + ' + str(b) + ' - 9 = 4' print '+ - -' print str(c) + ' - ' + str(d) + ' * ' + str(e) + ' = 4' print '/ * -' print str(f) + ' + ' + str(g) + ' - ' + str(h) + ' = 4' print '= = =' print '4 4 4'
相关文章推荐
- VBS脚本写的Windows硬件检测工具分享
- 用vbscript实现隐藏任务栏图标的脚本
- 用autoit编写第一个脚本(Hello World)
- VBS调用WMI快速关闭IE的脚本
- 收集的ROS防火墙脚本
- JSP脚本漏洞面面观
- 不错的批处理脚本 第一部分
- VBS脚本加密/解密VBS脚本(简易免杀版1.1)
- 不错的批处理脚本实例代码 第二部分
- 使用脚本和批处理清除电脑中的痕迹的代码第1/2页
- 让你的脚本说话
- Lua脚本获取喜马拉雅MP3音频地址
- 编程界主流脚本编程语言的比较和选择
- 批量文件查找替换功能的vbs脚本
- Powershell脚本的4种执行权限介绍
- Windows Powershell 执行文件和脚本
- PowerShell实现动态获取当前脚本运行时消耗的内存
- 脚本 MsAgent组件 微软精灵 揪出系统自带的宠物
- 百度空间备份脚本baidublogbak.vbs代码分析