这是题目要求:Write a function called calculate_cat_food_required. The function takes 2 arguments:
breed: The first argument is a string representing the type of cat
weight_in_kilograms: The second argument is the weight of the cat in kilograms
The function should return the number cups of cat food required for a cat with breed and weight specified by the arguments.
To calculate how many kilograms of cat food is required, we use the following formula.
If the cat is type "bengal", we need to feed it 0.2 cups of cat food per kilogram body weight.
If the cat is type "scottish_fold", we need to feed it 0.4 cups of cat food per kilogram body weight.
If the cat is type "fat_cat", we need to feed it 0.5 cups of cat food per kilogram body weight.
If the cat is any other breed, we need to feed it 0.3 cups of cat food per kilogram body weight.
Suppose you have a new litter of 3 "scottish_fold" kittens, each 0.9 kilograms. After your function implementation, you should call the calculate_cat_food_required function to calculate how many cups of cat food to prepare. Output the answer to the terminal.
这是题目要求的最后的样子:
calculate_cat_food_required("bengal", 4.0) -> 0.8
calculate_cat_food_required("bengal", 2.2) -> 0.44
calculate_cat_food_required("stray_cat", 4.0) -> 1.2
这是我写的:
def caluculate_cat_food_required(breed: str, weight_in_kilograms: float) ->str:
if breed == "bengal":
return (0.2) * weight_in_kilograms
elif breed == "scottish_fold":
return (0.4) * weight_in_kilograms
elif breed == "fat_cat":
return (0.5) * weight_in_kilograms
else:
return (0.3) * weight_in_kilograms
a = str(input())
b = float(input())
print(f"caluculate_cat_food_required("{a}", {b}) ->", caluculate_cat_food_required(a, b))
请问有什么办法可以直接变成 calculate_cat_food_required然后输入名字,数字然后 -> 函数给出的答案
print(f'caluculate_cat_food_required("{a}", {b}) ->', caluculate_cat_food_required(a, b))
改成这样子就可以,如有帮助,希望点一下下采纳