Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

task is to write a program that either says 'yes' this sequence is a palindrome or 'no' it is not. What to do Write a

task is to write a program that either says 'yes' this sequence is a palindrome or 'no' it is not.

What to do

Write a program that takes in a sequence of n-integers as input, and uses a recursive sub-routine to determine if the sequence of integers is a palindrome or not. Solutions that do not utilize a recursive sub-routine will not receive credit.

Hint: Remember a base case tells you when to stop recursing. Sometimes there are multiple triggers to stop, and thus multiple base cases. If you are stuck, try programming this iteratively with a loop first, then transforming it into a recursive solution.

EXPECTED INPUT You can assume the person using your program will only give good input (meaning they won't screw up and enter something like: "3, 5, $.56, oops". Allow the user to terminate giving input by entering a -1 (and make sure that -1 doesn't get included as a part of your number sequence)

EXPECTED OUTPUT The program should output the sequence of numbers, and a message showing the result of the palindrome analysis.

#follow the skeleton code and write the code where instructed.

from math import * # may or may not choose to use math library subroutines


def getInput(list):
print("Hello! This program will determine if a sequence of digits is a palindrome or not.")
print("Enter a sequence of digits (0 through 9) one after the other, enter a -1 when done.")
n = int(input("Enter a number: "))
while n != -1:
list.append(n)
n = int(input("Enter a number: "))


seq = []
getInput(seq)
print(seq)
# e.g.: a sequence of 1 0 5 1 -1
# gives: seq = [1,0,5,1]

####### YOUR CODE GOES BELOW ###############################


# NOTE: You are NOT allowed to use any loops in the code that you write. Writing a loop will result in a score of zero. Your solution MUST be recursive.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

Explain the guideline for job description.

Answered: 1 week ago

Question

What is job description ? State the uses of job description.

Answered: 1 week ago

Question

What are the objectives of job evaluation ?

Answered: 1 week ago

Question

Write a note on job design.

Answered: 1 week ago

Question

Does it avoid using personal pronouns (such as I and me)?

Answered: 1 week ago

Question

Does it clearly identify what you have done and accomplished?

Answered: 1 week ago