四分历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是我喜欢的语言,简洁,优美,容易使用.前两天,我很激 ...
随机推荐
- SQL索引未使用
针对自己曾经经历过的一道面试题,那些情况不走索引,于是搜索网络和书籍的一些资料,整理如下: 1.查询谓词没有使用索引的主要边界,换句话说就是select *,可能会导致不走索引.比如,你查询的是SEL ...
- 第四章 数据更新 4-1 数据的插入(INSERT 语句的使用方法)
一.什么是INSERT 用来插入数据的SQL就是INSERT语句. 二.INSERT 语句的基本语法. 列清单 值清单 列清单和值清单的列数必须保持一致,如果不一致会出错. 原则上,执行一次I ...
- Vue2学习笔记:组件(Component)
组件 组件(Component)是 Vue.js 最强大的功能之一.组件可以扩展 HTML 元素,封装可重用的代码.在较高层面上,组件是自定义元素, Vue.js 的编译器为它添加特殊功能.在有些情况 ...
- asp.net 一般处理程序接收上传文件的问题
在使用Html+ashx处理文件上传时,遇到上传文件超过4M的问题,首先HTML代码如下: <!DOCTYPE html> <html> <head> <me ...
- Linux内存管理(text、rodata、data、bss、stack&heap)
一.各内存区段的介绍 系统内的程序分为程序段和数据段,具体又可细分为一下几个部分: (1)text段-代码段 text段存放程序代码,运行前就已经确定(编译时确定),通常为只读,可以直接在ROM或Fl ...
- 转载:eclipse 搭建SSH项目(第一篇)
第一篇:原文地址:http://blog.csdn.net/aaaaaaaa0705/article/details/6288431(虽然没有具体的例子,不过逻辑性强点,比较容易看懂) SSH框架是最 ...
- NSOperation的使用细节 [2]
NSOperation的使用细节 [2] 这一节我们来写自定义nonconcurrent的operation,自定义nonconcurrent的operation很简单,重写main方法,之后处理好c ...
- 导出AD用户所属组,查询AD用户(aduser)
$ous="admin","bladmin","af","dd"for($i=0;$i -lt 2;$i++) { $o ...
- Linux crontab命令详解
crontab:定时任务的守护进程,精确到分,设计秒的我们一般写脚本 -->相当于闹钟 日志文件: ll /var/log/cron* 编辑文件: vim /et ...
- <Lord don’t move that mountain>
<Lord don’t move that mountain> Lord, don't move that mountain(主,不要移走高山) Give me strength to c ...