Python Programming: An Introduction to Computer Science, 3rd Ed.
3rd Edition
ISBN: 9781590282755
Author: John Zelle
Publisher: Franklin, Beedle & Associates
expand_more
expand_more
format_list_bulleted
Question
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
Expert Solution & Answer
Want to see the full answer?
Check out a sample textbook solutionStudents have asked these similar questions
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.
S is a set of strings recursively defined as follows.
Base case: Every variable from the set {a, b, c, d, e, f} is in S.
Recursive rules: If x = S and y = S, then:
1. (x + y) Є S
2. x.yЄ S
Indicate which expressions are in S.
☐ (d.e.a)
a+b
a.b.c
☐ (a + d).e
c++
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. 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 parameter.
Chapter 13 Solutions
Python Programming: An Introduction to Computer Science, 3rd Ed.
Ch. 13 - Prob. 1TFCh. 13 - Prob. 2TFCh. 13 - Prob. 3TFCh. 13 - Prob. 4TFCh. 13 - Prob. 5TFCh. 13 - Prob. 6TFCh. 13 - Prob. 7TFCh. 13 - Prob. 8TFCh. 13 - Prob. 9TFCh. 13 - Prob. 10TF
Ch. 13 - Prob. 1MCCh. 13 - Prob. 2MCCh. 13 - Prob. 3MCCh. 13 - Prob. 4MCCh. 13 - Prob. 5MCCh. 13 - Prob. 6MCCh. 13 - Prob. 7MCCh. 13 - Prob. 8MCCh. 13 - Prob. 9MCCh. 13 - Prob. 10MCCh. 13 - Prob. 1DCh. 13 - Prob. 2DCh. 13 - Prob. 3DCh. 13 - Prob. 4DCh. 13 - Prob. 5DCh. 13 - Prob. 1PECh. 13 - Prob. 2PECh. 13 - Prob. 3PECh. 13 - Prob. 4PECh. 13 - Prob. 5PECh. 13 - Prob. 6PECh. 13 - Prob. 7PE
Knowledge Booster
Similar questions
- Write a recursive function that displays a string reversely on the console using the following header: def reverseDisplay(value):For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forwardIn C++ Write a recursive function that displays a string reversely on the console using the following header:void reverseDisplay(const string& s) For example, reverseDisplay("abcd") displays dcba. Write a test programthat prompts the user to enter a string and displays its reversal.arrow_forwardA palindrome is a string that reads the same forwards or backwards; for example dad, mom, deed are palindromes (i.e., reversing a palindrome produces the same string). Use C++ Programing language Write a recursive, boolean-valued function, isPalindrome that takes a string as a parameter and returns whether the string is a palindrome. A string, s, is a palindrome if: s is the empty string or s consists of a single letter (which reads the same back or forward), or the first and last characters of s are the same, and the rest of the string (i.e., the second through next-to-last characters) form a palindrome. Write a test program that reads a string from the standard input device and outputs whether the input string is a palindrome or not.arrow_forward
- In C Language onlyarrow_forwardRecursive Palindrome! Recall that a palindrome is a string that reads the same forward and backward. Write a recursive function is_palindrome (s:str) -> bool to check whether a string s is a palindrome. Here's a hint: think about how you can use is_palindrome(t), where t is a substring of s, to help you decide whether s is a palindrome. Your Answer: 1 # Put your answer here 2 Submitarrow_forwardWrite a recursive function that parses a binary number as a string into a decimal integer. The function header is as follows:def binaryToDecimal(binaryString):Write a test program that prompts the user to enter a binary string and displays its decimal equivalent.arrow_forward
- python codearrow_forwardWrite a recursive function that parses a hex number as a string into a decimal integer. The function header is as follows:def hexToDecimal(hexString):Write a test program that prompts the user to enter a hex string and displays its decimal equivalent.arrow_forwardA palindrome is a string that’s spelled the same way forward and backward. Examples of palindromes include “radar” and “able was i ere i saw elba.” Write a recursive function testPalindrome that returns true if a string is a palindrome, and false otherwise. Note that like an array , the square brackets ( [] ) operator can be used to iteratethrough the characters in a string .arrow_forward
- Perform in C#arrow_forwardWrite a recursive function that converts a decimal number into a binary number as a string. The function header is as follows:def decimalToBinary(value): Write a test program that prompts the user to enter a decimal number and displays its binary equivalent.arrow_forwardWrite in C Language Spilitology Yosef is a peculiar fellow. He introduced the idea to study a string by splitting it into two, and he called it Splitology. Why split a string? We do not know. Didn’t we say that Yosef is a weird one? Yosef is interested in one particular type of string, a palindrome. A palindrome is a string that is the same for both forwards and backwards. Example of palindrome strings are “ada”, “taat”, and “radar”. On the other hand, string such as “taman” is not a palindrome; notice that “taman” becomes “namat” if read backwardsand it’s not the same as “taman”. As the idea of Splitology is still new, Yosef is investigating whether a string can be split into two non-empty strings such that each string is a palindrome. For example, the string “malamini” can be split into “malam” and “ini” while both of them are palindrome. Another example is “ababab”. It can be split into “aba” and “bab”, and both of them are palindrome. Note that “ababab” can also be split into…arrow_forward
arrow_back_ios
SEE MORE QUESTIONS
arrow_forward_ios
Recommended textbooks for you
- C++ Programming: From Problem Analysis to Program...Computer ScienceISBN:9781337102087Author:D. S. MalikPublisher:Cengage LearningEBK JAVA PROGRAMMINGComputer ScienceISBN:9781337671385Author:FARRELLPublisher:CENGAGE LEARNING - CONSIGNMENT
C++ Programming: From Problem Analysis to Program...
Computer Science
ISBN:9781337102087
Author:D. S. Malik
Publisher:Cengage Learning
EBK JAVA PROGRAMMING
Computer Science
ISBN:9781337671385
Author:FARRELL
Publisher:CENGAGE LEARNING - CONSIGNMENT