首页 > 其他 > 详细

if条件判断

时间:2019-10-28 17:59:31      阅读:80      评论:0      收藏:0      [点我收藏+]
正确示范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)
 
 
 

if条件判断

原文:https://www.cnblogs.com/myshuzhimei/p/11753863.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!