HW: Recursion II

In this practice HW you will create 2 programs that use strings, lists, and recursion.

Rx: <30 min Av: 30-60 min Sd: 60-90 min DNF: 90+ min

wheel.py

Write an iterative function count_vowels which takes a word as a parameter and returns the number of vowels in that string.

Write a recursive function sajak which takes a word as a parameter and returns the number of vowels in that string.

Test both functions by asking the user to enter a word, and printing the number of vowels found by each function.

Recommended Development Steps:

  1. Create a variable containing a single letter. Write an if statement to determine if that letter is a vowel or not. (Hint: use in)
  2. Put that if inside a loop that iterates through every letter in a string and prints out whether each letter is a vowel or not
  3. Update the loop to count the number of vowels and print the total at the end. This is the count_vowels function.
  4. For the recursive sajak function, think about how you can recursively print the first or last letter in a string, and implement it.
  5. Instead of printing the letter, print whether it’s a vowel.
  6. Instead of printing, count whether the letter is a vowel or not.

text.py

Write a function pyramid that takes a string of text as a parameter and outputs the text as follows:

Enter text: we love CS
w
we
we 
we l
we lo
we lov
we love
we love 
we love C
we love CS
we love C
we love 
we love
we lov
we lo
we l
we 
we
w

You may use either recursion or iteration in your solution. Note: if you use recursion, will need to implement 2 functions: one for printing top triangle of letters and one that prints the bottom triangle of letters. If using iteration, you will need 2 loops.

Test your functions by getting a string of text from the user and printing the results of both functions.

Recommended Development Steps:

  1. Create a string variable & print it out
  2. Think about the pattern of strings that are printed. Write a loop or a recursive function that successively prints out a substring from index 0 to the end. (Hint: use :)
  3. Now print the other way
  4. Get input from the user

Submission

Once you’re satisfied that your programs are working correctly, take a screenshot of each program open in the editor, with its output displayed in the console, and submit to google classroom. You should submit 2 screenshots.