Skip to content

Latest commit

 

History

History
74 lines (48 loc) · 1.17 KB

lab_2.md

File metadata and controls

74 lines (48 loc) · 1.17 KB

Strings

Exercise 1 (Warmup)

Write a program that repeats a string n times.

Example of output

string = "hello"
times = 5

output = "hellohellohellohellohello"

Exercise 2 (Shuffle)

Write a program that prompts the user for a stirng. Print the stirng in reverse order

Example of output

  Enter string:
  > of that im sure

Reverse is string: erus mi taht fo

Exercise 3 (Palindromes)

Write a program that prompts the user for a string and checks (and prints) if it is a palindrome. That is "a word, phrase, or sequence that reads the same backward as forward". Example: madam or nurses run. Note that, as in the second example, spaces (and capitalization) should be ignored.

Example of output

  Enter string:
  > madam

madam is a palindrome

Exericse 4 (Word Frequencies)

Write a program which reads a string and prints the word frequency for each word.

Example of output

Input
> sally sells seashells by the seashore
she sells seashells on the seashell shore
the seashells she sells are seashore shells

Word Frequencies:
sally 1
sells 3
seashells 3
by 1
the 3
seashore 2
she 2
on 1
seashell 1
shore 1
are 1
shells 1