四分历python实现
根据一个新加坡人的c代码改写成python代码
- ''' 四分历'''
- #
- zq = 0
- month = 0
- def main():
- global month
- year = 1
- rb_year = 0
- moon = 0 # number of new moon since beginning of ru bu year.
- tmonth = 0
- continues = False
- while year != 0:
- year = int(input("\nPlease Enter a year to do computation (range:85~236, 0 to exit):"))
- if year == 0:
- return
- if year < 85 or year > 236:
- print("\nCalculation of Si Fen Li doesn't apply to your input value.")
- input("\nPress Enter to continue.")
- #getch(continues);
- continue
- rb_year = (year + 9281) % 76
- tmonth = 14 + Leap_y(rb_year)
- print("月\t朔\t望\t长度\t中气\t时间\t时间\t时间")
- print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
- month = 11
- #zq = 0
- for moon in range(1, tmonth + 1):
- if moon % 8 == 0:
- #print("\n")
- pass
- print_s(rb_year, moon)
- month += 1
- if month > 12:
- month = 1
- input("\nPress Enter to continue.")
- # 润年
- def Leap_y( rbyear):
- isLeap = 0
- if ((rbyear - 1) * 235 ) % 19 >= 12:
- isLeap = 1
- return isLeap
- # 润月
- def Leap_m(rbyear, month):
- isLeap = 0
- completed_month = (rbyear - 1) * (235.0/19.0) + (month - 1)
- acd_first = (completed_month * (29.0+499.0/940.0) )
- acd_last = ((completed_month + 1.0) * (29.0+499.0/940.0) )
- qi_first = int(acd_first)/(30.0+14.0/32.0)
- qi_last = int(acd_last) / (30.0+14.0/32.0)
- if qi_first - int(qi_first) != 0:
- if int(qi_first) == int(qi_last) or qi_last == int(qi_last):
- isLeap = 1
- return isLeap
- # 打印结果
- def print_s(rbyear, moon):
- global zq
- global month
- name_s = acd_shuo(rbyear, moon)
- name_w = acd_wang(rbyear, moon)
- time_s = ( acd_shuo(rbyear, moon) - float(name_s) ) * 24.0
- time_w = ( acd_wang(rbyear, moon) - float(name_w) ) * 24.0
- length = int(acd_shuo(rbyear, moon + 1)) - name_s
- if Leap_m(rbyear, moon) == 0: #if is not a leap month.
- zq += 1
- name_q = acd_qi(rbyear, zq);
- time_q = ( acd_qi(rbyear, zq) - (float)(name_q) ) * 24.0
- print("{}\t1\t{:.1f}\t{:.3f}\t{:.1f}\t{:.3f}\t{:.3f}\t{:.1f}".format(month, time_s, name_w - name_s + 1, time_w, length, name_q - name_s + 1, time_q))
- else:
- month -= 1
- print("{}(Leap)\t1\t{:.1f}\t{:.3f}\t{:.1f}\t{:.3f}".format(month, time_s, name_w - name_s + 1, time_w, length))
- # 朔
- def acd_shuo(rbyear, moon):
- completed_month = ((rbyear - 1) * 235 / 19) + moon - 1
- return completed_month * (29.0+499.0/940.0)
- # 望
- def acd_wang(rbyear, moon):
- completed_month = ((rbyear - 1) * 235 / 19) + moon - 1
- return (completed_month + 0.5) * (29.0+499.0/940.0)
- # 气
- def acd_qi(rbyear, qi):
- completed_qi = ((rbyear - 1) * 12) + qi - 1
- return completed_qi * (30.0+14.0/32.0)
- if __name__ == '__main__':
- main()
四分历python实现的更多相关文章
- Python 历遍目录
Automate the Boring Stuff 学习笔记 01 使用 os 模块的 walk() 函数可以实现历遍目录的操作,该函数接收一个绝对路径字符串作为必选参数,返回三个参数: 当前目录—— ...
- python笔记4-遍历文件夹目录os.walk()
前言 如何遍历查找出某个文件夹内所有的子文件呢?并且找出某个后缀的所有文件 walk功能简介 1.os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. 2.walk()方 ...
- python学习历程之split()方法获取cmd mysql 结果集
if __name__=='__main__': FServerId = raw_input("Please input source id:") GetFileKey(FServ ...
- 使用Python进行描述性统计
目录 1 描述性统计是什么?2 使用NumPy和SciPy进行数值分析 2.1 基本概念 2.2 中心位置(均值.中位数.众数) 2.3 发散程度(极差,方差.标准差.变异系数) 2.4 偏差程度(z ...
- python与ruby的差别
1.引用文件差别 Ruby:同一目录下的文件,如/usr/local/ruby/foo.rb与/usr/local/ruby/bar.rb两个文件.如果直接在foo.rb中 require 'bar' ...
- python学习笔记:Day02
一.列表(list) 1.定义一个列表 name=["tom","jerry","12","13","lose ...
- 【转】你真的理解Python中MRO算法吗?
你真的理解Python中MRO算法吗? MRO(Method Resolution Order):方法解析顺序. Python语言包含了很多优秀的特性,其中多重继承就是其中之一,但是多重继承会引发很多 ...
- Python全栈之路---运算符与基本的数据结构
运算符 一.算术运算符: 练习: + 加法 两个对象相加 1 + 2得到3:'a' + 'b'得到'ab'. - 减法 一个数减去另一个数或者是负数 5 - 3得到2:-2得到一个负数 * 乘法 两个 ...
- Python简史
Python简史 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python是我喜欢的语言,简洁,优美,容易使用.前两天,我很激 ...
随机推荐
- 实用vim 130+命令
基本命令 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write ...
- Oracle EBS 数据访问权限集
SELECT frv.responsibility_name, fpo.profile_option_name, fpo.user_profile_option_name, fpv.profile_o ...
- 小鸡G4工程款 上手体验
前言:之前只是抱着试一试的态度在小鸡活动贴下报名,说实话之前并没有抱希望能够没选中.所以非常感谢小鸡团队给我的这次机会.这应该是我第一次参与厂家的内测活动.希望能给小鸡团队,给广大玩家带来一片实用的上 ...
- SCLAlertView-Swift
SCLAlertView-Swift https://github.com/vikmeup/SCLAlertView-Swift Animated Alert View written in Sw ...
- Unity调用安卓中的方法遇到的问题
最近在用U3D做一个简单的迷宫游戏,在项目中利用Unity制作游戏场景,在android中调用游戏场景,并在游戏结束后调用安卓方法,传递参数,退出游戏场景 查找网上资料,基本上Unity调用安卓的写法 ...
- C# 词法分析器(一)词法分析介绍
系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 虽然文章的标题是词法分析,但首先还是要从编译原理说开 ...
- Java并发编程--3.Lock
Lock接口 它提供3个常用的锁 lock() : 获不到锁就就一直阻塞 trylock() :获不到锁就立刻放回 或者 定时的,轮询的获取锁 lockInterruptibly() : 获不到锁时阻 ...
- HBase学习之路 (四)HBase的API操作
Eclipse环境搭建 具体的jar的引入方式可以参考http://www.cnblogs.com/qingyunzong/p/8623309.html HBase API操作表和数据 import ...
- 看到了一个pipeline例子,
pipeline { agent any options { timestamps() } parameters { string(name: 'GIT_BRANCH', defaultValue: ...
- 我的linux shell 脚本头部
#!/bin/bash #################################################### # version:1.01 # # link:http://www. ...