问题标题:
how_many_legsshouldtakeastringwhichisthenameofananimalandreturnanumberrepresentinghowmanylegstheanimalhas.Itneedstorecogniseatleastthefollowinganimals:human,chicken,horse,dog,spider,centipede.Ifitisgivenananimalit
问题描述:
how_many_legsshouldtakeastringwhichisthenameofananimalandreturnanumberrepresentinghowmanylegstheanimalhas.Itneedstorecogniseatleastthefollowinganimals:human,chicken,horse,dog,spider,centipede.Ifitisgivenananimalitdoesnotrecognise,itshouldprintanerrormessageandthenreturn0.
自己做的:
defhow_many_legs(name):
ifname=="horse"or"dog":
return"thisanimalhave4legs"
ifname=="chicken"or"human":
return"thisanimalhave2legs"
ifname=="spider":
return"thisanimalhave8legs"
ifname=="centipede":
return"thisanimalhave30or34legs"
else:
return"error,0"
它就只会打"thisanimalhave4legs",求更正,
刘爱莲回答:
def how_many_legs(name): if name == "horse" or name =="dog": return "t...
点击显示
英语推荐
热门英语推荐