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'