Spring Deals - hours only!Up to 70% off on all courses and bundles.-Close
Tuples as return types in functions
Tuples as records
7. Functions operating on tuples as real-world objects
List of tuples


Good job! When we use tuples as real-world objects, we typically create functions that operate on these tuples. Take a look:

def rate_deal(car_tuple):
  _, price, mileage = car_tuple
  if price > 50000 and mileage > 500000:
    print('This is not a good deal: high price and high mileage!')
  elif price < 10000 and mileage < 100000:
    print('This looks like a really good deal: low price and low mileage!')
    print('This looks like an OK deal.')

The function above is meant to estimate whether a given car is worth its price. Note that we used tuple unpacking on the second line to get access to certain elements of the tuple.


Create a function named calculate_new_salary(employee) that will return an employee's salary after the raise. The employee argument is a tuple with three elements: name, position, and salary, as shown in the template code.

The raise is calculated as 10% of salary for those whose position is 'SQL Analyst' and 5% of salary for all others.

Stuck? Here's a hint!

Unpack the tuple in the following way:

_, position, salary = employee

Then, if a position is equal to 'SQL Analyst', return salary*1.1. Otherwise, return salary*1.05.