The document contains a series of Python programming exercises that involve string manipulation. Each question requires the user to write a program to perform specific tasks such as counting characters, reversing strings, checking for palindromes, and finding substrings. The exercises range from basic string length calculations to more complex operations like counting vowels and analyzing character types.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
18 views8 pages
Yashi String File 1 PDF
The document contains a series of Python programming exercises that involve string manipulation. Each question requires the user to write a program to perform specific tasks such as counting characters, reversing strings, checking for palindromes, and finding substrings. The exercises range from basic string length calculations to more complex operations like counting vowels and analyzing character types.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8
Q1.
WAP to accept a string and display its length
without using any pre-defined function. s1=input("enter a string") i=0 for ch in s1: i+=1 print ("length is",i)
Q2.WAP to accept the name of a user and count
the number of vowels in that. s1=input("enter a string") i=0 for ch in s1: if ch in 'aeiouAEIOU': i+=1 print("vowels are",i) Q3.WAP to accept a string and count the number of words in that. s1=input("enter the string") i=1 for ch in s1: if ch==' ': i+=1 print("no. of words are",i)
Q4. WAP to accept a string and calculate its
length. str=input("enter a string") i=len(str) print("length of ",str,"is",i) Q5.WAP to accept a string and reverse it. str=input(“enter a string”) print(str[::-1])
Q6.WAP to accept a string and check if it is
palindrome or not. str=input("enter a string") i=len(str) i=i-1 str1=" " while i>=0: str1=str1+str[i] i =i-1 if str1==str: print("palindrome") else: print("not") Q7.WAP to accept a string and a character from user and check the occurrence of that character in the string. str=input("enter a string ") j=input(“enter a string character”) i=0 for j in str: if ch==j: i+=1 print("the occurence is",i) Q8.WAP to accept a string and count the number of capital letters ,small letters, digits and special characters in it. str=input("enter string") j=0 ch=0 n=0 a=0 for i in str: if i.isupper(): j+=1 elif i.islower(): ch+=1 elif i.isdigit(): n+=1 else: a+=1 print("capital letters",j,"small letters",ch,"digits",n,"special characters",a) Q9.WAP to accept a string and print the output in following format-: H HE HEL HELLHELL0 s1=input("enter a string") i=len(s1) for r in range(1,i+1): print(s1[0:r])
Q10.WAP to accept a string and display the
string without spaces.
s=input("enter a string") print (s.replace(" ","
")) Q11.WAP to accept a string and a sub string from user and display the freq. of that substring in the string.
s1=input("enter a string") s2=input("enter a substring") print(s1.count(s2))
Q12. WAP to accept a string and a substring and
print the second occurrence position of the substring. s1=input("enter a string") s2=input("enter a substring") if s1.count(s2)>=2: a=s1.index(s2) b=s1.find(s2,a+1) print(b) Q13.WAP to accept a string and display the ASCII code of each character. s1=input("enter a string") for ch in s1: print(ord(ch))
Q14.WAP to accept a string and substring and
display frequency of each vowel. s1=input("enter a string") for ch in 'aeiouAEIOU': s2=s1.count(ch) print(s2)