how-many-legs should take a string which is the name of an a

问题描述:

how_many_legs should take a string which is the name of an animal and return a number representing how many legs the animal has.It needs to recognise at least the following animals:human,chicken,horse,dog,spider,centipede.If it is given an animal it does not recognise,it should print an error message and then return 0.
自己做的:
def how_many_legs(name):
if name == "horse" or "dog":
return "this animal have 4 legs"
if name == "chicken" or "human":
return "this animal have 2 legs"
if name == "spider":
return "this animal have 8 legs"
if name == "centipede":
return "this animal have 30 or 34 legs"
else:
return "error,0"
它就只会打"this animal have 4 legs",求更正,
1个回答 分类:英语 2014-11-29

问题解答:

我来补答
def how_many_legs(name):
    if name == "horse" or name =="dog":
        return "this animal have 4 legs"
    if name == "chicken" or name =="human":
        return "this animal have 2 legs"
    if name == "spider":
        return "this animal have 8 legs"
    if name == "centipede":
        return "this animal have 30 or 34 legs"
    else:
        return "error,0"
 
 
展开全文阅读
剩余:2000