Posts

Showing posts with the label palindrome

Palindrome in python

Image
Palindrome in python Given a string, the program checks if the string is palindrome or not. A string is called palindrome if the reverse of the string is equal to the original string.  For example, the string 'madam' is a palindrome as the reverse of the string also forms the same word 'madam'. Meanwhile, the string 'Apple' is not a palindrome, the reverse of the string forms the word 'elppA'. Method 1 : In this method, the entire string is reversed. If the reversed string is equal to the original string then the string is said to be palindrome. Procedure : 1. Start. 2. Get the string from the user. 3. Reverse the string. 4. If the reversed string is equal to the original string, the string is palindrome. 5. Print the result. 6. End. Code : #get the string as input from the user s = str(input("Enter the string : ")) #reverse the string s1 = s[::-1] #if the given string is equal to the reversed string the string is palindrome if(s == s1): prin

Python exercise with solutions (Set 3)

Image
  1.To print all prime numbers in a given interval Sample input :  20 Sample Output : 2,3,5,7,11,13,17,19 Code : Output:   2. To check whether the given string is palindrome or not . A palindrome is a word that remains same even after reversing it. The code should print yes if the given word is palindrome and no if it is not a palindrome. Sample input : Madam Sample Output: Yes Code : Output : 3.To remove the duplicates in a list Sample input : [1,2,6,8,2,1,4,6,1,7,9] Sample Output : [1,2,6,8,4,7,9] Code : Output : 4. To print all items that are available for the given cost Sample input : 250 Sample Output : Apple Orange Banana Code : Output : 5.To capitalise the first letter of first name and last name of a person Sample input : henry bacos Sample Output : Henry Bacos Code : Output : For more exercises , 1. Python exercise-1 2. Python Exercise-2 3. Python Exercise-3 For python tutorials , 1. Introduction 2. Conditional statements (if---else...)