作业帮 > 英语 > 作业

how_many_legs should take a string which is the name of an a

来源:学生作业帮 编辑:大师作文网作业帮 分类:英语作业 时间:2024/11/12 05:40:28
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",求更正,
how_many_legs should take a string which is the name of an a
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"