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

Instruction

Good. We saw greater-than (>) and equals (==) operators in action, but there are a few more options. Take a look at the list:

  • less than: <,
  • greater than: >,
  • less than or equal: <=,
  • greater than or equal to: >=,
  • equals: ==,
  • not equal to: !=.

For instance:

password = input('Provide the password! ')
if password != 'sEcrEt':
  print('You shall not pass!')

The code above will print 'You shall not pass' if the user input does not equal 'sEcrEt'.

Exercise

Write a program that asks the user for their age and then prints information about user's driving status in England and Portugal.

  1. If the user is 17 or older, print:
    You can already drive a car in England
    Otherwise, print:
    You cannot drive a car in England yet
  2. If the user is 18 or older, print:
    You can already drive a car in Portugal
    Otherwise, print:
    You cannot drive a car in Portugal yet

Once you get the age using input(), write two independent if statements, one after another.