Python:过程型考核

我怕爱的太早我们不能终老 提交于 2019-12-20 19:17:01

一:利用年份公式推算12生肖,以及用if-else编写12星座和24节气。

1、PyQt设计界面:

在这里插入图片描述

2、对象命名:

在这里插入图片描述

3、源程序:
在这里插入代码片# 系统包
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
# 项目包
from Ui_MainWindow import Ui_MainWindow

class CMainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
    def __init__(self, parent = None):
        super(CMainWindow, self).__init__(parent)
        self.setupUi(self)

        # 主窗体设置
        self.show()
    def Sure(self):
        nian = int(self.txtNumber1.text())
        yue = self.txtNumber2.text()
        ri = self.txtNumber3.text()
        Months = self.txtNumber4.text()
        Day = self.txtNumber5.text()
        l = nian%12+1
        if l == 5:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是鼠年。"
        if l == 6:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是牛年。" 
        if l == 7:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是虎年。"
        if l == 8:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是兔年。"
        if l == 9:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是龙年。"
        if l == 10:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是蛇年。"
        if l == 11:
           strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是马年。"
        if l == 12:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是羊年。"
        if l == 1:
           strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是猴年。"
        if l == 2:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是鸡年。"  
        if l == 3:
            strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是狗年。"
        if l == 4:
           strOutnian =str(nian) + "年" + str(yue) + "月" + str(ri) + "日,今年是猪年。"
        self.labResult.setText(strOutnian)
        a = int(yue + ri)
        print(a)
        if a==101:
            strOutyueri = "今天是元旦节,我的星座是摩羯座"
        elif a <= 218 and a >= 120:
            strOutyueri = "我的星座是水瓶座"
        elif a <= 320 and a >= 219:
            strOutyueri = "我的星座是双鱼座"
        elif a ==401:
            strOutyueri = "今天是愚人节,我的星座是白羊座"   
        elif a <= 419 and a >= 321:
            strOutyueri = "我的星座是白羊座"
        elif a ==501:
            strOutyueri = "今天是劳动节,我的星座是金牛座"    
        elif a <= 520 and a > 420:
            strOutyueri = "我的星座是金牛座"
        elif a==601:    
            strOutyueri ="我的星座是双子座,今天是儿童节"
        elif a <= 621 and a >= 521:
            strOutyueri = "我的星座是双子座"
        elif a <= 722 and a >= 622:
            strOutyueri = "我的星座是巨蟹座"
        elif a <= 822 and a >= 723:
            strOutyueri = "我的星座是狮子座"
        elif a <= 922 and a >= 823:
            strOutyueri = "我的星座是处女座"
        elif a ==1001:
            strOutyueri ="今天是国庆节,我的星座是天秤座"    
        elif a <= 1023 and a >= 923:
            strOutyueri = "我的星座是天秤座"
        elif a <= 1122 and a >= 1024:
            strOutyueri = "我的星座是天蝎座"
        elif a==1213:
            strOutyueri ="今天是国家公祭日,我的星座是射手座"    
        elif a <= 1221 and a >= 1123:
            strOutyueri = "我的星座是射手座"
        else :
            strOutyueri = "我的星座是摩羯座"
        self.labResult.setText( self.labResult.text() + strOutyueri )
        b = int(Months + Day)
        print(b)
        if b <= 205 and b >= 203:
            strOutMonthsDay = "节气为春分"    
        elif b <= 220 and b >= 218:
           strOutMonthsDay = "节气为雨水"
        elif b <=307 and b >= 305:
           strOutMonthsDay = "节气为惊蛰"
        elif b <=322 and b >= 320:
           strOutMonthsDay= "节气为春分"
        elif b <=406 and b >= 404:
            strOutMonthsDay = "节气为清明"
        elif b <=421 and b >= 419:
            strOutMonthsDay = "节气为谷雨"
        elif b <= 507 and b >= 505:
            strOutMonthsDay = "节气为立夏"
        elif b <= 522 and b >= 520:
            strOutMonthsDay = "节气为小满"
        elif b <= 607 and b >= 605:
            strOutMonthsDay = "节气为芒种"
        elif b <= 621 and b >= 622:
            strOutMonthsDay = "节气为夏至"
        elif b <= 708 and b >= 706:
            strOutMonthsDay = "节气为小暑"
        elif b <= 724 and b >= 722:
            strOutMonthsDay = "节气为大暑"
        elif b <= 809 and b >= 807:
            strOutMonthsDay = "节气为立秋"
        elif b <= 824 and b >= 822:
            strOutMonthsDay = "节气为处暑"
        elif b <= 909 and b >= 907:
            strOutMonthsDay = "节气为白露"
        elif b <= 924 and b >= 922:
            strOutMonthsDay = "节气为秋分"
        elif b <= 1009 and b >=1008:
            strOutMonthsDay = "节气为寒露"
        elif b <= 1024 and b >= 1023:
            strOutMonthsDay = "节气为霜降"
        elif b <= 1108 and b >=1107:
            strOutMonthsDay = "节气为立冬"  
        elif b <= 1123 and b >= 1122:
            strOutMonthsDay = "节气为小雪"
        elif b <= 1208 and b >= 1206:
            strOutMonthsDay = "节气为大雪" 
        elif b <= 1223 and b >= 1221:
            strOutMonthsDay = "节气为冬至"  
        elif b <= 107 and b >= 105:
            strOutMonthsDay = "节气为小寒"    
        elif b <= 121 and b >= 120:
            strOutMonthsDay = "节气为大寒"
        elif b< 505 and  b>202:
            strOutMonthsDay="这个月为春天。"
        elif b<807 and b>505:
            strOutMonthsDay ="这个月为夏天。" 
        elif b<1008 and b>807:
            strOutMonthsDay ="这个月为秋天。"        
        else :
            strOutMonthsDay = "这个月为冬天。"
        self.labResult.setText(self.labResult.text() + ","+"," + strOutMonthsDay)    
if __name__ == '__main__':
    app = QtWidgets.QApplication(sys.argv)
    MainWindow = CMainWindow()
    sys.exit(app.exec_())
四、运行界面:

在这里插入图片描述

二、注解:

1:Python 使用def 开始函数定义,紧接着是函数名,括号内部为函数的参数。
2:如果程序中判断事件很多,全部用if的话,会遍历整个程序, 用elif 程序运行时,只要if或后续某一个elif之一满足逻辑值为True,则程序执行完对应输出语句后自动结束该轮if-elif(即不会再去冗余地执行后续的elif或else)。 提高效率。
3:nian%12+1意思是任意年份除以12加一的意思。
4:为什么二十四节气是按阳历计算的?
中国古代是一个农业社会,气候对农耕有非常重要的影响,因而中国古人对气候变化的研究十分关心。经过长期的观察,总结,把北半球的气候变化分成24种状况以及昼(白天)夜(晚上)的实际长短,制定了24节气【具体节气的含义见楼上】。由地理气象理论知道,地球气候的变化的根本原因是日照的变化,而日照的变化与地球和太阳的相对位置有关,也就是气候的周期性变化与(太)阳历对应。由此,24节气就与阳历吻合了。
农历实际上应该叫(太)阴历,是以月亮的圆缺变化为周期的,这个对农耕没有太大直接关系,但对潮汐有直接影响。每逢满月时潮水特别大,因此我国沿海的渔,农民在生产中就非常注意阴历。
中国古代对天象的观察主要是月亮和星星,而历法的制定主要是对天象的观察,古语有“斗转星移”表示日子的变化就是一个反映。因此中国古代主要式样的历法是阴历。阳历在西方科技发展起来并影响到中国后才引进使用。
5:24节气和12星座时间需自行查询。另外文章量较大,要有足够的耐心。

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!