If-else Workshop in Python
Write a condition that will check whether the number specified in the variable is even or not.
Let's say you have a variable with a string. If it contains the character 'a', then let it be replaced with '!'.
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.
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.
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.
The following code is given:
tst = 'abcdef'
if len(tst) > 20:
print('string is too long')
else:
print('string is too short')
Rewrite it using the ternary operator.