Programs using Strings :
str1 = input ("Enter a
string: ")
str2 = ' '
index=-1
for i in str1:
str2 += str1[index]
index -= 1
print ("The given string = {
} \n The Reversed string = { }".format(str1, str2))
if (str1==str2):
print ("Hence, the given
string is Palindrome")
else:
print ("Hence, the given is
not a palindrome")
Output : 1
Enter a string: malayalam
The given string = malayalam
The Reversed string = malayalam
Hence, the given string is
Palindrome
Output : 2
Enter a string: welcome
The given string = welcome
The Reversed string = emoclew
Hence, the given string is not a
palindrome
*
* *
* * *
* * * *
* * * * *
str1=' * '
i=1
while i<=5:
print (str1*i)
i+=1
Output
*
* *
* * *
* * * *
* * * * *
str1=input ("Enter a string:
")
str2="aAeEiIoOuU"
v,c=0,0
for i in str1:
if i in str2:
v+=1
else:
c+=1
print ("The given string
contains { } vowels and { } consonants".format(v,c))
Output
Enter a string: Tamilnadu School
Education
The given string contains 11
vowels and 15 consonants
str1="ABCDEFGH"
str2="ate"
for i in str1:
print ((i+str2),end='\t')
Output
Aate Bate Cate Date Eate Fate Gate Hate
def rem_vowels(s):
temp_str=''
for i in s:
if i in "aAeEiIoOuU":
pass
else:
temp_str+=i
print ("The string without
vowels: ", temp_str)
str1= input ("Enter a
String: ")
rem_vowels (str1)
Output
Enter a String: Mathematical
fundations of Computer Science
The string without vowels:
Mthmtcl fndtns f Cmptr Scnc
def count(s, c):
c1=0
for i in s:
if i == c:
c1+=1
return c1
str1=input ("Enter a String:
")
ch=input ("Enter a character
to be searched: ")
cnt=count (str1, ch)
print ("The given character
{} is occurs {} times in the given string".format(ch,cnt))
Out Put
Enter a String: Software
Engineering
Enter a character to be searched:
e
The given character e is occurs 3
times in the given string
Related Topics
Privacy Policy, Terms and Conditions, DMCA Policy and Compliant
Copyright © 2018-2023 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.