String All operation in Python

 

Following Assignment will Perform following operations:

1. Take a string from user and reverse it.
2. Count Number of words in the given string.
3. Count vowels,Consonents and special Charaters in the given string.
4. Reverse each word of the given string.
5. Return Largest word of the string.
IDE Used:- https://www.onlinegdb.com/ πŸ™‚

”’
Following Assignment will Perform following operations:
1. Take a string from user and reverse it.
2. Count Number of words in the given string.
3. Count vowels,Consonents and special Charaters 
in the given string.
4. Reverse each word of the given string.
5. Return Largest word of the string.
IDE Used:- https://www.onlinegdb.com/ πŸ™‚
”’

#1. This function takes input from user and reverse it.

s = input(β€œPlease Enter a Sentance: β€œ# initializing string 
print(β€œ1. β€œ,s[::-1])

#2. This function takes input from user and 
count the number of the words.

u = len(s.split())    #using split() to count words in string
print (β€œ2.  The number of words in string are : β€œ + str(u))
#3.This Function will Count vowels,Consonents and 
special Charaters in the given string

b = 0;   #b for vowel
h = 0;   #h for Consonents
a = 1;   #a for special charater
for i in range(0,len(s)):   
    #Checks whether a character is a vowel  
    if s[iin (β€˜a’,β€œe”,β€œi”,β€œo”,β€œu”):  
        b = b + 1;  
    elif (s[i] >= β€˜a’ and s[i] <= β€˜z’):  
        h = h + 1;
print(β€œ3.  Total number of vowel are:”,b,
β€œTotal Consonents are:”,h,β€œTotal Special Character are:”,a,β€œ.”)
#4.This Function Reverse each word of the given string.

print(β€œ4.  Reverse words of this string are:”)
print(”    β€œ,s[::-1])
#5.This Part Return The Largest word of the string.

sentence = s
m = max(sentence.split(), key=len#Finding longest word
print(β€œ5.  Longest word is: β€œm#Displaying longest word


Output:–

PS C:UsersSHEOKAND> & β€œC:/Program Files/Python39/python.exe” β€œe:
/MCA/2 Sem/GJU SEM II/Python/Assignments/A1_Strings.py”

Please Enter a Sentance: I am Form Narwana
1. anawraN mroF ma I
2. The number of words in string are : 4
3. Total number of vowel are: 5 Total Consonents are: 6
Total Special Character are: 1 .
4. Reverse words of this string are:
anawraN mroF ma I
5. Longest word is: Narwana
PS C:UsersSHEOKAND>
    

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *