PR Assignment6

You might also like

You are on page 1of 2

Assignment No : 6

Title:
Write a python program that accepts a string from user and perform following string
operations- i. Calculate length of string ii. String reversal iii. Equality check of two strings
iii. Check palindrome ii. Check substring
Aim:
Write a python program that accepts a string from user and perform following string
operations- i. Calculate length of string ii. String reversal iii. Equality check of two strings iii.
Check palindrome ii. Check substring
Theory:
In computer programming, a string is a sequence of characters
The Python String len() method is used to retrieve the length of the string.
There is no built-in function to reverse a String in Python. The fastest way is to use a slice that
steps backwards, -1 .
In python substring is a sequence of characters within another string, In python, it is also referred
to as the slicing of string
A palindrome is a sequence of the word, phrases, or numbers that read the same backward as
forward
Algorithm:
Step1: Start
Step2: Add palindrome and substring using def function
Palindrome _ s==s[::-1] and substring_ index=s.find(sub) return true or false
Step3: Input 2 strings
Steps4: Use while function and set the input choice from 0 to 6
Step5: Print the Questions(eg: palindrom, substring, length,etc)
Step6: Calculations: a) use len function to calculation the length of the string.
b) to reverse; [s1::-1]
c) to check equal; s1==s2 , print true or false
d) palindrome ; if s1 == true else false, same condition for s2
e) check substring; if (s1,s2) == true else false
f) else exit if the input value in not between the range.
Step7: Stop
Conclusion:
Able to compare between the two strings, find length of strings, to check the palindrome
and substrings are correct or not, reverse the string by using def, while , if else keywords in
python programming.

You might also like