Python CSC242 Correct Answers

Provides correct solutions for programming tasks related to Python in CSC242.

Lucy Gray
Contributor
4.2
50
5 months ago
Preview (2 of 4 Pages)
100%
Purchase to unlock

Loading document content...

Preview Mode

Sign in to access the full document!

Python CSC242 Correct Answers

Page 1

Python CSC242 Correct Answers 1a. Write a non - recursive function vowels() that accepts a character string and counts and returns the number of vowels (aeiou) in the string. 1b. Write a recursive function rvowels() that accepts a character string and counts and returns the number of vowels (aeiou) in the string. This solution should not include any loops. A global variable for the counter is acceptable. (Hint: one possible solution is to “chop” the string down until you are left with a single character .) 1c. Using the test string ‘this is a test to see if my program can accurately count the vowels’ and the time operation described in the book on page 371 in the function timing, time the non - recursive solution and the recursive solution. Does this test prov ide any useable proof? Explain. Place both your functions into one file. Dropbox your Word document showing all code and output, along with your Python file. In the Word document, include your answer to the above question: Does this test provide any useabl e proof? Explain. 2. Write a recursive function which accepts a string and its length and determines if the string is a palindrome. A palindrome is a string that reads the same frontwards and backwards. Hint: compare the first character with the last character. Equal or not ? Go from there.

Page 2

Python CSC242 Correct Answers 1a. Write a non - recursive function vowels() that accepts a character string and counts and returns the number of vowels (aeiou) in the string. 1b. Write a recursive function rvowels() that accepts a character string and counts and returns the number of vowels (aeiou) in the string. This solution should not include any loops. A global variable for the counter is acceptable. (Hint: one possible solution is to “chop” the string down until you are left with a single character .) 1c. Using the test string ‘this is a test to see if my program can accurately count the vowels’ and the time operation described in the book on page 371 in the function timing, time the non - recursive solution and the recursive solution. Does this test prov ide any useable proof? Explain. Place both your functions into one file. Dropbox your Word document showing all code and output, along with your Python file. In the Word document, include your answer to the above question: Does this test provide any useabl e proof? Explain. 2. Write a recursive function which accepts a string and its length and determines if the string is a palindrome. A palindrome is a string that reads the same frontwards and backwards. Hint: compare the first character with the last character. Equal or not ? Go from there.

Study Now!

XY-Copilot AI
Unlimited Access
Secure Payment
Instant Access
24/7 Support
Document Chat

Document Details

Related Documents

View all