Python Programming: An Introduction to Computer Science, 3rd Ed.
Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
Question
Book Icon
Chapter 13, Problem 3PE
Program Plan Intro

Palindrome

Program plan:

  • Define a function “palindrome()”.
    • If the condition “firstRun == True”is true.
    • Iterate a for loop.
      • Call a function “replace()”.
    • Call the function “lower()”.
    • If the condition “len(xStr) < 2”is true.
      • Return true
    • Check another condition “xStr[0] == xStr[-1]”.
      • Set the value of “xStr”.
      • Call the function “palindrome()”.
      • Return true.
    • If the conditions do not satisfy
      • Return false
  • Define “main()” function.
    • Scan for the input values.
    • If the condition is true
      • Print the statement.
    • If the condition is not true.
      • Print the statement.
  • Calling the main function

Blurred answer
Students have asked these similar questions
Help me please: A palindrome is a string that reads the same both forward and backward. For example, the string madam is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Prompt the user for a string. If the string is a palindrome output a message in the following format: madam is a palindrome else Hello is not a palindrome Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.
Write a recursive function to print all the permutations of a string. For example, for the string abc, the printout is:abcacbbacbcacabcba(Hint: Define the following two functions. The second function is a helper function.def displayPermuation(s):def displayPermuationHelper(s1, s2): The first function simply invokes displayPermuation(" ", s). The secondfunction uses a loop to move a character from s2 to s1 and recursively invokes t with a new s1 and s2. The base case is that s2 is empty and prints s1 to the console.)Write a test program that prompts the user to enter a string and displays all its permutations.
A palindrome is a sentence that contains the same sequence of letters reading it either forwards or backwards. A classic example is '1\.ble was I, ereI saw Elba." Write a recursive function that detects whether a string is apalindrome. The basic idea is to check that the first and last letters of thestring are the same letter; if they are, then the entire string is a palindromeif everything between those letters is a palindrome.There are a couple of special cases to check for. If either the first orlast character of the string is not a letter, you can check to see if the restof the string is a palindrome with that character removed. Also, when youcompare letters, make sure that you do it in a case-insensitive way.Use your function in a program that prompts a user for a phrase andthen tells whether or not it is a palindrome. Here's another classic fortesting: '1\. man, a plan, a canal, Panama!"
Knowledge Booster
Background pattern image
Similar questions
SEE MORE QUESTIONS
Recommended textbooks for you
Text book image
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning