您的位置:首页 > 其它

if语句的简单使用

2014-09-14 13:50 483 查看
#!/usr/bin/python

#-*- coding:utf8 -*-

from __future__ import division

#简单的讲解if的使用 elif switch的使用

def cmp(a, b):

if a > b:

print "a is bigger than b"

elif a == b:

print "a is eual to b"

else:

print "a is smaller than b"

#a = input("please enter a num: ")

#b = input("please enter other num: ")

#cmp(a,b)

#现在来介绍raw_input的使用

num = raw_input("please enter a num: ")

num = int(num)

print "the num is: ", num

string = raw_input("please enter a string: ");

print "the string is: ",string

#现在来演示elif的使用

score = input("enter the score: ")

if(score >= 90) and (score<=100):

print "A"

elif(score >= 80) and (score <= 90):

print "B"

elif(score >= 70) and (score <= 80):

print "C"

elif(score >= 60) and (score <= 70):

print "D"

else:

print "E"

#现在来演示一下switch效果 注意 python中没有switch关键字额

#from __future__ import division

m = 1

n = 2

operator = "/"

result = {

"+": m + n,

"-": m - n,

"*": m * n,

"/": m / n

}

print "the result is: ",result.get(operator)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: