pythonif语句的3种形式例题?
1、单分支:
if 3>2:
print(' OK')
2、双分支:
jitu,tui=map(int,input('请输入鸡兔总数和腿总数:').split())
tu=(tui-jitu*2)/2
if int(tu)==tu:
print('鸡:{0},兔:'{1}'.format(int(jitu-tu),int(tu))
else:
print('数据不对,无解')
3、多分支:
def fun(score):
if score>100 or score<0:
return' wrong score.must between 0 and 100.'
elif score>=90:
return 'A'
elif score>=80:
return 'B'
elif score>=70:
return 'C'
elif score>=60:
return 'D'
else:
return 'E'
Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有