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
来源:学生作业帮助网 编辑:作业帮 时间:2024/07/04 21:12:58
![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](/uploads/image/z/11936066-50-6.jpg?t=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%3Ahuman%2Cchicken%2Chorse%2Cdog%2Cspider%2Ccentipede.If+it+is+given+an+animal+it)
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
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 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
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"