Function basics
More advanced concepts


Perfect! You can also invoke your functions inside other functions. Take a look:

def contains_digits(word):
  for letter in word:
    if letter.isnumeric():
      return True
  return False

def contains_letters(word):
  for letter in word:
    if letter.isalpha():
      return True
  return False

def validate_password(password):
  if not contains_letters(password) or not contains_digits(password):
    return False
    return True

First, we defined two functions that check whether (a) a given word contains digits and (b) a given word contains letters. Next, we used these functions inside another function that checks whether a user's password is in the proper format (i.e., whether it contains at least one letter and at least one digit).


Create a function that will convert gross salary to net salary in an imaginary country. Name the function convert_gross_to_net(salary). The function should print the following information:

Your salary gross: {x}
Salary after social contribution: {y}
Net salary after tax: {z}

Create two helper functions: calculate_social_contribution(amount) and calculate_tax(amount), and use them later in your main function.

The following rules apply:

First, the social contribution is calculated. It is 0 for salaries below 200, 100 for salaries below 1000, and 200 for salaries greater than or equal to 1000. The calculate_social_contribution(amount) function should return only those values (0, 100 or 200).

Once the social contribution has been deducted, you need to calculate the tax from the remaining amount. The tax is 10% for any amount up to 3000. If the amount is greater than 3000, the tax is 300 + 20% of all the amount above 3000. For instance, for amount=5000, the tax will be:

300 + (5000-3000)*20% = 300 + 2000 * 20% = 300 + 400 = 700

The calculate_tax(amount) function should return 700 in that case.