根据一个新加坡人的c代码改写成python代码

  1. ''' 四分历'''
  2.  
  3. #
  4. zq = 0
  5. month = 0
  6.  
  7. def main():
  8. global month
  9. year = 1
  10. rb_year = 0
  11. moon = 0 # number of new moon since beginning of ru bu year.
  12. tmonth = 0
  13. continues = False
  14.  
  15. while year != 0:
  16. year = int(input("\nPlease Enter a year to do computation (range:85~236, 0 to exit):"))
  17.  
  18. if year == 0:
  19. return
  20. if year < 85 or year > 236:
  21. print("\nCalculation of Si Fen Li doesn't apply to your input value.")
  22. input("\nPress Enter to continue.")
  23. #getch(continues);
  24. continue
  25.  
  26. rb_year = (year + 9281) % 76
  27. tmonth = 14 + Leap_y(rb_year)
  28.  
  29. print("月\t朔\t望\t长度\t中气\t时间\t时间\t时间")
  30. print("- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -")
  31.  
  32. month = 11
  33. #zq = 0
  34. for moon in range(1, tmonth + 1):
  35. if moon % 8 == 0:
  36. #print("\n")
  37. pass
  38. print_s(rb_year, moon)
  39. month += 1
  40. if month > 12:
  41. month = 1
  42.  
  43. input("\nPress Enter to continue.")
  44.  
  45. # 润年
  46. def Leap_y( rbyear):
  47. isLeap = 0
  48. if ((rbyear - 1) * 235 ) % 19 >= 12:
  49. isLeap = 1
  50. return isLeap
  51.  
  52. # 润月
  53. def Leap_m(rbyear, month):
  54. isLeap = 0
  55. completed_month = (rbyear - 1) * (235.0/19.0) + (month - 1)
  56. acd_first = (completed_month * (29.0+499.0/940.0) )
  57. acd_last = ((completed_month + 1.0) * (29.0+499.0/940.0) )
  58. qi_first = int(acd_first)/(30.0+14.0/32.0)
  59. qi_last = int(acd_last) / (30.0+14.0/32.0)
  60.  
  61. if qi_first - int(qi_first) != 0:
  62. if int(qi_first) == int(qi_last) or qi_last == int(qi_last):
  63. isLeap = 1
  64.  
  65. return isLeap
  66.  
  67. # 打印结果
  68. def print_s(rbyear, moon):
  69. global zq
  70. global month
  71. name_s = acd_shuo(rbyear, moon)
  72. name_w = acd_wang(rbyear, moon)
  73. time_s = ( acd_shuo(rbyear, moon) - float(name_s) ) * 24.0
  74. time_w = ( acd_wang(rbyear, moon) - float(name_w) ) * 24.0
  75. length = int(acd_shuo(rbyear, moon + 1)) - name_s
  76.  
  77. if Leap_m(rbyear, moon) == 0: #if is not a leap month.
  78. zq += 1
  79. name_q = acd_qi(rbyear, zq);
  80. time_q = ( acd_qi(rbyear, zq) - (float)(name_q) ) * 24.0
  81. 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))
  82. else:
  83. month -= 1
  84. print("{}(Leap)\t1\t{:.1f}\t{:.3f}\t{:.1f}\t{:.3f}".format(month, time_s, name_w - name_s + 1, time_w, length))
  85.  
  86. # 朔
  87. def acd_shuo(rbyear, moon):
  88. completed_month = ((rbyear - 1) * 235 / 19) + moon - 1
  89. return completed_month * (29.0+499.0/940.0)
  90.  
  91. # 望
  92. def acd_wang(rbyear, moon):
  93. completed_month = ((rbyear - 1) * 235 / 19) + moon - 1
  94. return (completed_month + 0.5) * (29.0+499.0/940.0)
  95.  
  96. # 气
  97. def acd_qi(rbyear, qi):
  98. completed_qi = ((rbyear - 1) * 12) + qi - 1
  99. return completed_qi * (30.0+14.0/32.0)
  100.  
  101. if __name__ == '__main__':
  102. 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. 实用vim 130+命令

    基本命令 :e filename Open filename for edition :w Save file :q Exit Vim :q! Quit without saving :x Write ...

  2. Oracle EBS 数据访问权限集

    SELECT frv.responsibility_name, fpo.profile_option_name, fpo.user_profile_option_name, fpv.profile_o ...

  3. 小鸡G4工程款 上手体验

    前言:之前只是抱着试一试的态度在小鸡活动贴下报名,说实话之前并没有抱希望能够没选中.所以非常感谢小鸡团队给我的这次机会.这应该是我第一次参与厂家的内测活动.希望能给小鸡团队,给广大玩家带来一片实用的上 ...

  4. SCLAlertView-Swift

    SCLAlertView-Swift https://github.com/vikmeup/SCLAlertView-Swift   Animated Alert View written in Sw ...

  5. Unity调用安卓中的方法遇到的问题

    最近在用U3D做一个简单的迷宫游戏,在项目中利用Unity制作游戏场景,在android中调用游戏场景,并在游戏结束后调用安卓方法,传递参数,退出游戏场景 查找网上资料,基本上Unity调用安卓的写法 ...

  6. C# 词法分析器(一)词法分析介绍

    系列导航 (一)词法分析介绍 (二)输入缓冲和代码定位 (三)正则表达式 (四)构造 NFA (五)转换 DFA (六)构造词法分析器 (七)总结 虽然文章的标题是词法分析,但首先还是要从编译原理说开 ...

  7. Java并发编程--3.Lock

    Lock接口 它提供3个常用的锁 lock() : 获不到锁就就一直阻塞 trylock() :获不到锁就立刻放回 或者 定时的,轮询的获取锁 lockInterruptibly() : 获不到锁时阻 ...

  8. HBase学习之路 (四)HBase的API操作

    Eclipse环境搭建 具体的jar的引入方式可以参考http://www.cnblogs.com/qingyunzong/p/8623309.html HBase API操作表和数据 import ...

  9. 看到了一个pipeline例子,

    pipeline { agent any options { timestamps() } parameters { string(name: 'GIT_BRANCH', defaultValue: ...

  10. 我的linux shell 脚本头部

    #!/bin/bash #################################################### # version:1.01 # # link:http://www. ...