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)
#-*- 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语句使用规则简单概述
- python 笔记 if语句的简单使用 《笨办法学Python》习题29 ——1.2
- if..else 语句的简单使用
- 使用if语句的简单代码
- 关于if语句的使用简单举例,如果输入的数字不在有效范围内可继续输入 .cpp
- Python中if语句的说明和简单使用实例
- (hdu 简单题 128道)hdu 2004(if语句的基本使用)
- Python中if语句的说明和简单使用实例
- 重构:一个简单的IF语句
- if语句能在Orchestration中使用?
- 在Repeater控件中使用if语句
- C_判断语句if与else的组合使用
- 【BASH】使用更少的if语句
- 请定义一个宏,比较两个数a、b的大小,不能使用大于、小于、if语句。
- SQL中的IF ELSE(CASE语句的使用)
- 转载:JSP中使用IF语句
- C_判断语句if与else的嵌套使用
- 使用shell的if else fi语句和注意的地方
- 初学JavaSprit简单的if...else if 语句
- 从零学习freemarker(3)IF语句的使用