您的位置:首页 > 编程语言 > Python开发

Python学习(3)——if语句

2014-04-15 16:40 288 查看
虽然在之前接触过C、C++、Java等,但是还是觉得Python写出来的好看o(≧v≦)o~,简洁明了!

score = raw_input("score:")
score=int(score)
if(score >= 90) and (score <= 100):
print "A"
elif(score >= 80) and (score < 90):
print "B"
elif(score >= 60) and (score < 80):
print "C"
else:
print "D"


  

  if语句的嵌套

i = 5
if i > 1:
print 'i bigger than 1'
print 'good'
if i>2:
print 'i bigger thatn 2'
print 'even better'


python中没有switch语句, switch可以使用if...elif...else实现。

if, elif, else之后必须要有冒号(:), 之后的代码需要增加一层缩进。


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