Introduction
Conditional statements
Summary

Instruction

Finally, we can also use the not operator to introduce negation:

user_input = input('Please enter a number: ')
if (not user_input.isnumeric()):
  print('This is not a number!')
else:
  print('This is a correct number!')

The if code in the fragment above will be executed only if isnumeric() does not return True.

Exercise

An Internet website has the following password policy for user accounts:

  1. passwords must be at least 8 characters long,
  2. passwords cannot start with the @ character.

Write a program that will ask the user for a password and will check whether it satisfies the conditions. If the conditions are met, write:

Correct password!

Otherwise, write:

Incorrect password!

Use the following two functions: len(string) and string.startswith('x').

Stuck? Here's a hint!

You will need to use both and and not in the if statement.