0% found this document useful (0 votes)
0 views

Assignment Python 2

The document is a Python script that prompts the user to input a string and calculates various metrics including the length of the string, the number of words, vowels, consonants, and digits. It also sums the digits in the string and determines if the sum is even or odd. The results are printed to the console.

Uploaded by

Chetan Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Assignment Python 2

The document is a Python script that prompts the user to input a string and calculates various metrics including the length of the string, the number of words, vowels, consonants, and digits. It also sums the digits in the string and determines if the sum is even or odd. The results are printed to the console.

Uploaded by

Chetan Jaiswal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

print("Enter the string")

s = input()

print("length of string is ",len(s))

l = s.split(" ")

no_of_words = 0

for x in l:

no_of_words += 1

vowels = ['A', 'E', 'I', 'O', 'U', 'a', 'e', 'i', 'o','u']

numbers = ['0','1','2','3','4','5','6','7','8','9']

no_of_vowel = 0

no_of_cons = 0

no_of_digits =0

print("Total no. of words in string are ", no_of_words)

for i in range(0 , no_of_words):

for x in range(0 , len(l[i])) :

if l[i][x] in vowels:

no_of_vowel += 1

elif l[i][x] in numbers:

no_of_digits += 1

else:

no_of_cons += 1

print("total vowels = ", no_of_vowel)

print("total consonents = ", no_of_cons)


print("total digits = ", no_of_digits)

sum_of_digits = 0

print("digits are :")

for dig in range(0 , len(s)):

if s[dig] in numbers:

sum_of_digits += int(s[dig])

print(s[dig])

if sum_of_digits % 2 == 0:

print("sum of digits is EVEN")

else :

print("sum of digits is ODD")

You might also like