if条件判断

正确示范1
score = int(raw_input('input score:\n'))
if score >= 90:
    grade = 'A'
if score <90 and score >= 60:
    grade = 'B'
if score < 60:
    grade = 'C'
print '%d belongs to %s' % (score,grade)
 
正确示范2
score = int(raw_input('input score:\n'))
if score >= 90:
    grade = 'A'
elif score >= 60:
    grade = 'B'
else:
    grade = 'C'
print '%d belongs to %s' % (score,grade)
 
 
 
错误示范1
score = int(raw_input('input score:\n'))
if score >= 90:
    grade = 'A'
#下面的if和else作为一个组合了,会导致99 belongs to C。
if score <90 and score >= 60:
    grade = 'B'
else:
    grade = 'C'
print '%d belongs to %s' % (score,grade)
 
错误示范2
score = int(raw_input('input score:\n'))
if score >= 90:
    grade = 'A'
#下面的if和else作为一个组合了,会导致99 belongs to B。
if score >= 60:
    grade = 'B'
else:
    grade = 'C'
print '%d belongs to %s' % (score,grade)
 
 
 
posted @ 2019-10-28 17:41  数之美  阅读(249)  评论(0编辑  收藏  举报