Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(c) 20 points Words, sentences, and numbers that read the same forward as backward are called palindromes. The number 43134 , the date 02/02/2020 (ignoring

image text in transcribed
(c) 20 points Words, sentences, and numbers that read the same forward as backward are called palindromes. The number 43134 , the date 02/02/2020 (ignoring the slashes), the word "madam", and the sentence "Was it a car or a cat I saw?", all are palindrome examples. Write the function palindrome (n,m) that takes as input a positive integer number n and its number of digits, m, and returns True if the number is palindrome, False otherwise. For example, palindrome (25652,5) returns True, while palindrome (6786,4) returns False. Note that the code that you have written in homework 2 for the function getKthDigit (n,k) can greatly come to help in this case. The function getKthDigit (n,k) returned the k-th digit of the number n, starting from the rightmost digit (corresponding to k equal to 0 ). For instance, getKthDigit (7463,2) returns 4 . To help you writing the function palindrome(), the code of the function getKthDigit() is reported here. Look at its one-line code and use it wisely for writing the palindrome() function (which is expected to be quite short too, maybe 4-6 lines of code). def getKthDigit (n,k) : return (n // (10** k)) \% 10 Hint: inspect the digits from left to right and from right to left, if they are always the same the number is palindrome

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

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions

Question

I am paid fairly for the work I do.

Answered: 1 week ago

Question

I receive the training I need to do my job well.

Answered: 1 week ago