Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Conditional statements
Summary

Instruction

Perfect. Sometimes, more than one condition needs to be met in order to execute a part of code. To that end, we can use Boolean operators. The first operator we'll look at is and:

nationality = input('What is your nationality? ')
age = input('What is your age? ')

if (nationality == 'German' and int(age) > 25):
  print('You are eligible to apply.')
else:
  print('Sorry, only German citizens above 25 can apply.')

The code above checks two conditions at the same time:

  1. nationality must be equal to 'German'.
  2. age must be greater than 25.

When using and, BOTH conditions must be met to execute the code after if. If at least one of the conditions returns False, the code after else will be executed.

Exercise

In the Polish language, every name that ends with the letter -a is a female name. The only exception is Kuba, which is a male name.

Write a program that will ask the user for a name and will either print:

  • This is a female name
  • This is a male name

Hint: use the function name.endswith('a'), which returns True if the name ends with an 'a'.

Stuck? Here's a hint!

In your if statement, you should decide that a name is female if:

  • it ends with 'a',
  • it does not equal 'Kuba'.