Build function that iterates through a dictionary via specific keys mentioned in the function

My function contains a global car dictionary, I’m trying to build a function that would sum up three car prices and return it. If you don’t find a car then it returns specifically the name of the car mentioned in the function, stating that it doesn’t exist.

Here’s my dict:

CARS = {
  "Honda Accord": 2500,
  "Ford Mustang": 30000,
  "Mercedez Benz C63": 54000,
  "Audi A4": 35000,
  "Toyota Camry": 2300
}

And here’s how the function should work:

def func(car1,car2,car3):
    for k in CARS.keys():
        return CARS[car1] + CARS[car2] + CARS[car3]
    #if k not in CARS.keys():
    #    return f'{k} not found'

The last elif is where I’m facing an issue. The first for loop works fine. I want to output that if the user has entered i.e ‘Skoda’ and it isn’t in the dictionary, it should print out Skoda not found. Also, is there a neater way of doing this ? TIA

Edit Hey all, okay, so apologies for the weird syntax and logic. I’m basically taking in 3 strings and I want to check whether those strings are in the dictionary, if they are, return the sum of their values else, print out those specific car models that haven’t been mentioned in the dictionary and say “car model” not found. That’s it.

Answer

This works in Python 3.8.5:

CARS = {
  "Honda Accord": 2500,
  "Ford Mustang": 30000,
  "Mercedez Benz C63": 54000,
  "Audi A4": 35000,
  "Toyota Camry": 2300
}

def func(car1,car2,car3):
    cars_list = [car1,car2,car3]
    try:
        return sum([CARS[i] for i in cars_list])
    except Exception as e:
        return f'{e.args[0]} not found'
print(func('Honda Accord', 'Ford Mustang', 'Audi A4'))
print(func('Honda Accord', 'Ford Mustang', 'Skoda'))

Output:

67500
'Skoda not found'