Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Exercise #3: (16 points: 8 + 8) 3.1. Write a function in Python, printStringProp

ID: 3881254 • Letter: E

Question

Exercise #3: (16 points: 8 + 8) 3.1. Write a function in Python, printStringProperties(), with NO LOOPS, which accepts a string from console and: (a) print the characters that have even indexes. (b) print the input string in reverse order. (c) print True if the input string is a palindrome, False otherwise. Note: A palindrome is a string which is same read forward or backwards. For example the string 12321 is a palindrome.

Example:

The input string is => 0123456789

The characters that have even indexes are => 02468

The string in reverse order => 9876543210

The input string is a palindrome => False

Explanation / Answer

--Program in Python----

#Function to print input string properties
def printStringProperties(inputString):
#Print input string
print("The input string is => "+inputString)
#Print even indices using range in python
print("The characters that have even indexes are => "+inputString[1::2])
#Reverses the string
orgString=inputString
reverseString=inputString[::-1]
print("The string in reverse order => "+reverseString)
#Checks if it is palindrome or not
if(reverseString==orgString):
print("The input string is a palindrome => True")
else:
print("The input string is a palindrome => False")
  
  


#Main
Input = raw_input("Enter the string:")
#Call the function
printStringProperties(Input)

---Output---

Enter the string:0123456789
The input string is => 0123456789
The characters that have even indexes are => 13579
The string in reverse order => 9876543210
The input string is a palindrome => False