CLASS 11 : Chapter 8: Strings Computer Science (083)

Vijaya Kumar Chinthala
4 min readAug 31, 2023

2023–24

Chapter 8: STRINGS

  1. Write a program to count the number times a character occurs in a given string.
  2. Write a program which accepts a string and replaces all vowels in the string with “*”.
  3. Write a program to input a string and print it in reverse order without creating a new string.
  4. Write a program to input a string and print it in reverse order using a for loop.
  5. Write a program to input a string and check if the string is palindrome or not( A string is called palindrome if it reads the same backwards as forward, mom is a palindrome).
  6. Write a program to input lines of the text from the user until enter is pressed. Count the total number of characters in the text(including white spaces), total no of digits, total number of special symbols and total no of words in the given text,( Assume each word is separated by one space).
  7. Write a program to input lines of text and apply the title function if entered text has more than one word.
  8. Write a program to input a string and character and delete the occurrence of the character in the given string.
  9. Write a program to input a string having some digits. Print the sum of digits present in its string.
  10. Write a program to input a text of lines,( Assume each word is separated by one space). Replace space with “-”.
  1. Write a program to count the number times a character occurs in a given string.
a=str(input("Enter the text"))
b=str(input("Enter the char"))
print("char occurs",a.count(b))

Output:

Enter the text computer science
Enter the chare
char occurs 3

OR

a=str(input("Enter the text"))
b=str(input("Enter the char"))
count=0
for i in a:
if i==b:
count+=1
print("Char occurs",count)

Output:

Enter the text computer science
Enter the char e
char occurs 3

2. Write a program which accepts a string and replaces all vowels in the string with “*”.

a=str(input("Enter the text"))
b=["a","e","i","o","u","A","E","I","o","U"]
for i in a:
if i in b:
print("*",end="")
else:
print(i,end="")

Output:

Enter the text computer science
c*mp*t*r sc**nc*

3. Write a program to input a string and print it in reverse order without creating a new string.

a=str(input("Enter the text"))
print(a[::-1])

Output:

Enter the text computer science
ecneics retupmoc

4. Write a program to input a string and print it in reverse order using a for loop.

a=str(input("Enter the text"))
b=""
for i in a:
b=i+b
print(b)

Output:

Enter the text computer science
ecneics retupmoc

5. Write a program to input a string and check if the string is palindrome or not( A string is called palindrome if it reads the same backwards as forward, mom is a palindrome).

a=str(input("Enter the text"))
b=""
for i in a:
b=i+b
if a==b:
print("palindrome")
else:
print("not a palindrome")

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
Enter the text mom
palindrome
====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
Enter the text python
not a palindrome

6. Write a program to input lines of the text from the user until enter is pressed. Count the total number of characters in the text(including white spaces), total no of digits, total number of special symbols and total no of words in the given text,( Assume each word is separated by one space).

a=str(input("Enter the text"))
print("No of chars:",len(a))
alpha=digit=space=spl=0
for i in range(len(a)):
if a[i].isalpha():
alpha+=1
elif a[i].isdigit():
digit+=1
elif a[i].isspace():
space+=1
else:
spl+=1
print("no of alphabets:",alpha)
print("no of digits:",digit)
print("no of words:",space+1)
print("no of special symbols :",spl)

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
Enter the text python is simple programming language@ 123
No of chars: 41
no of alphabets: 32
no of digits: 3
no of words: 6
no of special symbols : 1

7. Write a program to input lines of text and apply the title function if entered text has more than one word.

a=str(input("Enter the text"))
if " " in a:
b=a.split(" ")
if len(b)>1:
print(a.title())
else:
print("One word")

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text python
One word
====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text python is very simple language
Python Is Very Simple Language

8. Write a program to input a string and character and delete the occurrence of the character in the given string.

a=str(input("enter the text"))
b=str(input("enter the char"))
print(a.replace(b,""))

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the textcomputer science
enter the chare
computr scinc

OR

a=str(input("enter the text"))
b=str(input("enter the char"))
temp=""
for i in a:
if i==b:
i=""
temp+=i
print(temp)

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text computer science
enter the chare
computr scinc

9. Write a program to input a string having some digits. Print the sum of digits present in its string.

a=str(input("enter the text"))
temp=0
for i in a:
if i.isdigit():
temp+=int(i)
print("sum of digits:",temp)

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text computer456
sum of digits: 15

10. Write a program to input a text of lines,( Assume each word is separated by one space). Replace space with “-”.

a=str(input("enter the text"))
print(a.replace(" ","-"))

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text we have computer science in class11
we-have-computer-science-in-class11

OR

a=str(input("enter the text"))
temp=""
for i in a:
if i==" ":
i="-"
temp+=i
print(temp)

Output:

====== RESTART: C:/Users/rainb/OneDrive/Desktop/q.py ======
enter the text we have computer science in class11
we-have-computer-science-in-class11

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response