if条件判断

正确示范1
score = int(raw_input('input score: '))
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: '))
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: '))
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: '))
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)
 
 
 
原文地址:https://www.cnblogs.com/myshuzhimei/p/11753863.html