Python_第2章_4,5,6,7(余下)

一、实验目的和要求

    实例5:使用比较运算符

    实例6:输入语句,条件判断语句

    实例7:引入输入语句的判断

二、实验过程

    采用Python

三、实验过程

    根据《零基础学Python》(全彩版)的课程实例代码

四、代码及其结果

    1.代码

  实例5:使用比较运算符比较大小关系
                python = 95
                english = 92
                c = 89
                print('python = ' + str(python) + ' english = ' +str(english) + ' c = ' +str(c) + '\n')

                print('python < english的结果:' + str(python < english))
                print('python > english的结果:' + str(python > english))
                print('python == english的结果:' + str(python == english))
                print('python != english的结果:' + str(python != english))
                print('python <= english的结果:' + str(python <= english))
                print('english >= c的结果:' + str(python >= c))
  实例6:参加手机店打折活动

                print('\n手机店正在打折,活动进行中……')
                strWeek = input('请输入中文星期(如星期一):')
                intTime = int(input('请输入时间中的小时(范围:0~23):'))
                if (strWeek == '星期二' and  (intTime >= 10 and intTime <= 11)) or (strWeek == '星期五' and (intTime >= 14 and intTime <= 15)):
                    print('恭喜您,获得了折扣活动参与资格,快快选购吧!')
                else:
                    print('对不起,您来晚一步,期待下次活动……')
   实例7:改进计算BMI
                height = float(input('请输入您的身高(单位为米):'))
                weight = float(input('请输入您的体重(单位为千克):'))
                bmi=weight/(height*height)
                print('您的BMI指数为:'+str(bmi))
                # 判断身材是否合理
                if bmi<18.5:
                    print('您的体重过轻 ~@_@~')
                if bmi>=18.5 and bmi<24.9:
                    print('正常范围,注意保持 (-_-)')
                if bmi>=24.9 and bmi<29.9:
                    print('您的体重过重 ~@_@~')
                if bmi>=29.9:
                    print('肥胖 ^@_@^')

  2.结果

 

 

 





posted @ 2022-09-14 20:30  JunerC  阅读(45)  评论(0)    收藏  举报