首页 > 代码库 > python-5

python-5

条件语句

循环语句

                条件语句

                    流控制语句-分支结构

                    if 条件:

                        语句执行

                    else:

                    执行语句

                    

                    if 条件:

                    elif:

                    elif:

                    else:

 

练习:

价格大于等于五百以后打印出价格或者显示原价

jiage=input(‘...‘)
if jiage >=500 :
        print int(jiage)*0.8
else:
        print jiage
round(价格,2) 取变量后的两位小数截止。

 

无限个商品,总价大于500则八折,小于五百不打折输出各种信息

c=0
jiage=1
b=0
while round(jiage,2) >0  :
        jiage=input(‘jiage‘)
        b=round(b,2)+round(jiage,2)
        print (‘zongjia‘),(b),(‘shuru[0]wanbi‘)
if b>500 :
        c=b*0.8
        print (‘zhekou‘),(c)
else:
        print (‘meiyouzhekou‘),(b)

本文出自 “11627223” 博客,请务必保留此出处http://11637223.blog.51cto.com/11627223/1916280

python-5