码迷,mamicode.com
首页 > 其他好文 > 详细

if语句

时间:2018-03-03 12:16:02      阅读:102      评论:0      收藏:0      [点我收藏+]

标签:整数   alt   put   print   int   style   2.0   ima   打印   

 -----------------以下截图来自王大鹏老师的教学

技术分享图片

 

 

if (3 < 89):
    print("True")  # 假如3小于89,则打印字符串“True”
    
if (3 < 9):
    pass  # pass语句,占位符号,不执行任何语句,不起任何实际作用

 

 

#V1.0 有逻辑问题,跟业务期望不一致
score = 87
if (score >= 90):
    print("A")
if (score >= 80 ):
    print("B")
if (score >= 70 ):
    print("C")
if (score >= 60 ):
    print("D")
if (score < 60):
    print("E")

#V2.0 初级if语句,主要是理解思路,但是不是标准程序员的写作格式
score = 87
if (score >= 90):
    print("A")
if (score >= 80 and score<90):
    print("B")
if (score >= 70 and score<80):
    print("C")
if (score >= 60 and score<70):
    print("D")
if (score < 60):
    print("E")

 

 

技术分享图片

简单的练习:判断是否及格

score = input("请输入你的成绩:")  # input返回的是string类型,不能直接跟整数比较
score = int(score)  # 通过int对象可以把字符串类型转换成整数数字类型
if (score >= 60):
    print("你已经及格!")
else:
    print("对不起,你需要重考!")

 

增加业务需求:能够判断好成绩,及格和不及格

score = input("请输入你的成绩:")
score = int(score)  # 通过int对象可以把字符串类型转换成整数数字类型
if (score >= 90):
    print("A")
    print("You are the best!")
    print("Thank You!")
else:
    if (score >= 60):
        print("成绩及格")
    else:
        print("成绩不及格")

 

技术分享图片

 

score = 87
if (score > 90):
    if (score >= 95):
        print("You are the best!")
else:
    print("一般般啦")

 

练习;模拟上海出租车收费系统

1. 3公里以内,13元;

2. 15公里以内,每公里2.3元;

3.超过15公里,加收空驶费,为单价的50%,即:2.3+2.3*0.5=3.45元

 

if语句

标签:整数   alt   put   print   int   style   2.0   ima   打印   

原文地址:https://www.cnblogs.com/jameskane/p/8495859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!