Write a Python program according to the task. Predictprocessing of the specified exceptional situation.


Joined
May 28, 2022
Messages
7
Reaction score
1
Task: Given text. Find, count and remove all spaces
Exceptional:The original text does not contain spaces
 
Ad

Advertisements

Joined
May 11, 2022
Messages
58
Reaction score
5
Python:
x = input("desired text to be analyzed ")
numspace = 0
i = 0

while i < len(x):
   if x[i] == " ":
      x = x[:i] +x[i+1:]
      numspace += 1
   else:
      i+=1
print(numspace,x)
 
Ad

Advertisements


Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top