概述
#!/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)
最后
以上就是负责滑板为你收集整理的if语句的简单使用的全部内容,希望文章能够帮你解决if语句的简单使用所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复