Week 3: Exercises

1. AEIOU

Write a program that reads a string on a single line and prints "vowels" if the string contains any vowels, otherwise "no vowels".

2. ASCII or Unicode

Read a string and print either 'ascii' if the string contains only ASCII characters, 'unicode' otherwise.

3. Spaces In Between

Read a string and write it out with a space between each adjacent pair of characters.

Enter string: waffle
w a f f l e

4. Double Or Nothing

Read a string and print 'double' if any two adjacent characters are the same, or 'nothing' otherwise.

Enter string: abacuses
nothing
===
Enter string: lionesses
double

5. Capitalizing Words

Write a program that reads a string and capitalizes all words in the string. For this exercise, words are sequences of characters separated by one or more spaces. (Do not use the built-in method title(), which does the same thing.)

Sample input:

  one    fine     day

Output:

  One    Fine     Day

6. Password Generator

Write a program that generates a random password with 10 lowercase letters. The password should contain alternating consonants and vowels.

Sample outputs:

  kimolonapo
  ritilenora

7. String Comparison

Write a program that reads two string S and T, each on its own line. The program should print the string that is lexicographically greater, i.e. the string that appears later in dictionary order. Do not use the built-in string comparison operator '>'.

Enter S: limerick
Enter T: limeade
limerick

8. All Upper

Write a program that reads a string of ASCII characters and makes all lowercase letters uppercase without using the library function upper.

Sample input:

100 Spires and Towers

Sample output:

100 SPIRES AND TOWERS

9. Largest product in a series

Solve Project Euler's problem 8, reading the input number as a series of lines from standard input.