Answer to Question #303093 in Python for rgtd

Question #303093

Define a function named "countCharacter" that accepts a sentence as parameter (string) and


calculate the total number of letters, total number of uppercase letters, total number of


lowercase letters, total number of digits and total number of characters that is not letter and


not digit.


The function will then return a list of integer representing total number of letters , number of


letters with uppercase and lowercase, number of digits and any other character beside letters


and digits.


Suppose the following input is supplied to the function


"Hell0 WorlD!!!4567" the function will return a list with the following values


[9, 3, 6, 5, 4]


1
Expert's answer
2022-02-27T03:58:26-0500

string=input("Enter string:")

char=0

count1=0

count2=0

for i in string:

    char=char+1

for i in string:

    if(i.islower()):

       count1=count1+1

    elif(i.isupper()):

       count2=count2+1

cont1=0

for i in string:

    if(i.isdigit()):

       cont1=cont1+1

def countCharacter(string): 

   special_char= 0

  

   for i in range(0, len(string)): 

     ch = string[i]

     if (string[i].isalpha()): 

       continue

     elif (string[i].isdigit()):

       continue

     else: 

       special_char += 1

 

   if special_char >= 1:  

     print( char,count2,count1,cont1,"{}".format(special_char))

if __name__ == '__main__' :

   countCharacter(string)

 


Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS