求解答,急,本人真的是没有办法了

img


本人可能没有学习Python的天赋,想半天也不能达到完美,仅需要第二问,比较基础的一个程序,请高抬贵手,解答完美可追加赏金
12月1日12:00截止哦

img


# 1

rabis = []
for i in range(2):
    rabi = input(f'请输入第{i+1}只兔子的名字:')
    rabis.append(rabi)
print(f"My rabbits' name are {rabis[0]} and {rabis[1]}")
fish = {}
count = input(f'请输入你有几条红色的鱼:')
fish['red'] = int(count)
count = input(f'请输入你有几条蓝色的鱼:')
fish['blue'] = int(count)
print(f'I have {fish["red"]} red finish and {fish["blue"]} blue fish.')


# 2
def pet(food1,food2,food3=None):
    if food3 != 'water':
        print('I need some water for pets')
    else:
        food = ['carrot' , 'vegetable' , 'water']
        print("There are3 kind of food for pet, the food list is:")
        print("------ {}".format(food1))
        print("------ {}".format(food2))
        print("------ {}".format(food3))
        return(food)

pet('carrot' , 'vegetable')
pet('carrot' , 'vegetable' , 'water')

# 3
food_label = {'food1':'carrot',"food2":'vegetable','food3':'water'}
food_label['food1'] = 'grass'
food_label['food4'] = 'snack'

for i, name in food_label.items():
    print('{} is {}'.format(i , name))

这思路不是蛮清晰么?你还有啥问题?

干嘛要追求完美😂能跑就行

相当于对传入的三个参数判定是否包含water,有则打印三个参数,没有的话把第三个参数替换为water,然后打印

def inputName():
    rabbitName = [input("input the first rabbit name:"), input("input the second rabbit name::")]
    print("My rabbits' name are '{}' and '{}'".format(rabbitName[0], rabbitName[1]))
    fishName = {input("input the first fish name:"): 1, input("input the second fish name:"): 1}
    keys = list(fishName.keys())
    print("I hava {} {} fish and {} {} fish".format(fishName[keys[0]], keys[0], fishName[keys[1]], keys[1]))


def pet(food1, food2, food3):
    if food1 != 'water' and food2 != 'water' and food3 != 'water':
        print("I need some water for pets")
    else:
        print("There are 3 kind of food of pet, the food list is:")
        print("------ {}".format(food1))
        print("------ {}".format(food2))
        print("------ {}".format(food3))
    return [food1, food2, food3]


def three(foodList):
    food_label = {'food1': foodList[0], 'food2': foodList[1], 'food3': foodList[2], 'food4': input("input food4:")}
    for key in food_label:
        print("{} is {}".format(key, food_label[key]))


if __name__ == '__main__':
    # one
    inputName()
    # two
    foods = pet(input("input food1: "), input("input food2: "), input("input food3: "))
    # three
    three(foods)

img