根据一个新加坡人的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实现的更多相关文章

  1. Python 历遍目录

    Automate the Boring Stuff 学习笔记 01 使用 os 模块的 walk() 函数可以实现历遍目录的操作,该函数接收一个绝对路径字符串作为必选参数,返回三个参数: 当前目录—— ...

  2. python笔记4-遍历文件夹目录os.walk()

    前言 如何遍历查找出某个文件夹内所有的子文件呢?并且找出某个后缀的所有文件 walk功能简介 1.os.walk() 方法用于通过在目录树种游走输出在目录中的文件名,向上或者向下. 2.walk()方 ...

  3. python学习历程之split()方法获取cmd mysql 结果集

    if __name__=='__main__': FServerId = raw_input("Please input source id:") GetFileKey(FServ ...

  4. 使用Python进行描述性统计

    目录 1 描述性统计是什么?2 使用NumPy和SciPy进行数值分析 2.1 基本概念 2.2 中心位置(均值.中位数.众数) 2.3 发散程度(极差,方差.标准差.变异系数) 2.4 偏差程度(z ...

  5. python与ruby的差别

    1.引用文件差别 Ruby:同一目录下的文件,如/usr/local/ruby/foo.rb与/usr/local/ruby/bar.rb两个文件.如果直接在foo.rb中 require 'bar' ...

  6. python学习笔记:Day02

    一.列表(list) 1.定义一个列表 name=["tom","jerry","12","13","lose ...

  7. 【转】你真的理解Python中MRO算法吗?

    你真的理解Python中MRO算法吗? MRO(Method Resolution Order):方法解析顺序. Python语言包含了很多优秀的特性,其中多重继承就是其中之一,但是多重继承会引发很多 ...

  8. Python全栈之路---运算符与基本的数据结构

    运算符 一.算术运算符: 练习: + 加法 两个对象相加 1 + 2得到3:'a' + 'b'得到'ab'. - 减法 一个数减去另一个数或者是负数 5 - 3得到2:-2得到一个负数 * 乘法 两个 ...

  9. Python简史

    Python简史 作者:Vamei 出处:http://www.cnblogs.com/vamei 欢迎转载,也请保留这段声明.谢谢! Python是我喜欢的语言,简洁,优美,容易使用.前两天,我很激 ...

随机推荐

  1. Oracle EBS 应收事务处理取值

    SELECT ct.org_id ,ct.attribute1 bu_id --核算主体编号 ,ct.attribute2 dept_id --部门编号 ,hca.account_number ,hp ...

  2. Oracle 查看锁情况

    /*查看锁(lock)情况*/ SELECT ls.osuser os_user_name, ls.username user_name, decode(ls.type, 'RW', 'Row wai ...

  3. MySQL8.0初体验

    MySQL8.0的官方社区开源版出来有段时间了,而percona的8.0版本还没有正式对外发布(已发布测试版),一直以来也没安装体验下这个号称质的飞跃的版本,今天正好有些时间就下了安装体验体验. 一. ...

  4. 水晶报表自定义纸张大小打印 (Crystal Report Print with custom paper size)

    System.Drawing.Printing.PrintDocument doc = new PrintDocument(); doc.PrinterSettings.PrinterName = & ...

  5. 产生渐变色的view

    产生渐变色的view 效果 源码 https://github.com/YouXianMing/UI-Component-Collection // // GradientColorView.h // ...

  6. Linux 系统的日志目录

    连接时间的日志 连接时间日志一般由/var/log/wtmp和/var/run/utmp这两个文件记录,通过who查看 who /var/log/wtmp [连接时间日志] who /var/log/ ...

  7. matlab中关于函数句柄、feval函数以及inline函数的解析 (转)

    http://blog.sina.com.cn/s/blog_7bff755b010180l3.html MATLAB函数句柄 函数句柄(Function handle)是MATLAB的一种数据类型. ...

  8. [BZOJ 4031][LOJ 2122][HEOI 2015] 小Z的房间

    [BZOJ 4031][LOJ 2122][HEOI 2015] 小Z的房间 题意 给定一个 \(n\times m\) 的矩阵, 一些格子是障碍, 相邻的格子(四联通)之间可以连边, 求把非障碍的格 ...

  9. IIS : Add the server variable name to the allowed server variable list.

    IIS下设置反向代理访问时报错:将服务器变量名添加到允许的服务器变量列表中. 1.打开IIS: 2.打开要添加变量的站点: 3.打开URL Rewrite: 4.在右列上,选择“查看服务器变量(Vie ...

  10. React & TypeScript

    之前看了一下 TypeScript 的知识,但是一直没有上手,最近开始结合 React 和 TypeScript 一起尝试了一下,感受还是很好的,所以写一下笔记. 环境配置没有参考其他东西,就是看了下 ...