Skip to content

Latest commit

 

History

History
56 lines (34 loc) · 1.56 KB

File metadata and controls

56 lines (34 loc) · 1.56 KB

Unit 3 Practice

Exercise 2 - String Comparisons

2.1

  • Assign a letter to a variable to serve as the secret answer

  • Ask the user to enter a letter, assign it to a variable

  • if the user's letter is the same as the answer, inform the user they've guessed correctly. Otherwise, inform them they've erred and display the correct answer.

2.2

  • Ask the user for a word

  • Ask the user for a letter

  • Assign the word and the letter to variables

  • Use the keyword in to determine if the letter is in the word

  • Tell the user if the letter is in the word. Display the letter in uppercase

    Enter a word: umbrella
    Enter a letter: b
    
    output:
    The word "umbrella" contains the letter "B".
    
    -------------------
    Enter a word: umbrella
    Enter a letter: z
    
    output:
    The word "umbrella" does not contain the letter "Z".
    

2.3

If the word contains the letter, tell the user how many times the letter is in the word

  Enter a word: giraffe
  Enter a letter: f

  output:
  The word "giraffe" contains the letter "F" 2 times.

2.4

Using string methods, determine if the string the user entered contains only letters, no spaces, numbers or special characters.

if the string contains characters other than letters, inform the user that those characters aren't allowed.

Exercise 2 solution