Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Introduction
Quick recap
8. The in operator
Indexing and slicing
Summary

Instruction

Good job! To check if a character is present in a string, we can use the in operator:

user_input = input('Enter your email address: ')
if '@' not in user_input:
  print('Not a correct email address!')

The code above checks whether the @ character is present in the e-mail address provided.

Exercise

Ask the user to do the following:

  • Provide the name of a country that does not contain any lowercase a or e letters. (Write the following prompt: 'The country is: ')
  • If the user provides a correct string (i.e., one with no a or e inside it), print: You won... unless you made this name up! Otherwise, print: You lost!

(By the way, possible answers include Hong Kong, Cyprus, and Togo.)

Stuck? Here's a hint!

Use:

if 'a' in country or 'e' in country: