If-else Workshop in Python

Задание 1

Write a condition that will check whether the number specified in the variable is even or not.

Задание 2

Let's say you have a variable with a string. If it contains the character 'a', then let it be replaced with '!'.

Задание 3

Given a variable that will store the user's email. Check if it contains the '@' symbol. If it does not, let the user re-enter the correct email.

Задание 4

Given a variable that will store the username. Write a condition that will check the length of the name. If the length is less than 3, then a message will be displayed that the name is too short. If the length is between 3 and 20 characters, it is correct. If the length exceeds 20 characters, then a message will be displayed that the name needs to be shortened.

Задание 5

Given a variable that will store the password for logging into the site. Write a check to ensure that the password is not empty. Also check that its length is within 6 - 14 characters.

Задание 6

The following code is given:

pythontst = 'abcdef'

if len(tst) > 20:
  print('string is too long')
else:
  print('string is too short')

Rewrite it using the ternary operator.