Python for loop

Question:21
Write a python script to take input for a string , check and print total upper case alphabets present in the string?
Sol:

n=input("Enter any string ")
u=0
for i in n:
    print(i)
    if(i>='A' and i<='Z'):
        u=u+1
print("total upper case alphabets = ",u)

Output:

Enter any string HeLLO
H
e
L
L
O
total upper case alphabets = 4
>>>

Question:22
Write a python script to take input for a string , check and print total digits present in the string?
Sol:

n=input("Enter any string ")
d=0
for i in n:
    print(i)
    if(i>='0' and i<='9'):
        d=d+1
print("total digits = ",d)

Output:

Enter any string he123llo
h
e
1
2
3
l
l
o
total digits = 3
>>>

Question:23
Write a python script to take input for a string , check and print the following:
1. total alphabets.
2. total upper case alphabets
3. total lower case alphabets
4. total digits
5. length of the string
6. total spaces
7. total special characters
Sol:

n=input("Enter any string ")
leng=0
a=0
la=0
ua=0
d=0
sp=0
spl=0
for i in n:
    print(i)
    leng=leng+1
    if((i>='A' and i<='Z') or (i>='a' and i<='z')):
        a=a+1
        if(i>='A' and i<='Z'):
            ua=ua+a
        else:
            la=la+1
    elif(i>='0' and i<='9'):
        d=d+1
    elif(i==' '):
        sp=sp+1
    else:
        spl=spl+1

print("total length = ",leng)
print("total alphabets = ",a)
print("total upper case alphabets = ",ua)
print("total lower case alphabets = ",la)
print("total digits = ",d)
print("total spaces = ",sp)
print("total special characters = ",spl)

Output:

Enter any string Hell123 $%^ hi
H
e
l
l
1
2
3

$
%
^

h
i
total length = 14
total alphabets = 6
total upper case alphabets = 1
total lower case alphabets = 5
total digits = 3
total spaces = 2
total special characters = 3
>>>

Question:24
Write a python script to take input for a string , check and print total vowels present in the string?
Sol:

code

Output:

Question:25
Write a python script to take input for a string , check and print total consonants present in the string?
Sol:

code

Python Basic Programming Tutorial

Python Introduction     Getting started in Python Programming      Python propgramming fundamentals     Python Operators    Python If Condition     Python for loop    Python range construct      Python While loop    break and continue statements     Different looping techniques     Python List     Python String     Python Functions    Python Inbuilt Functions     Python Recursion     Using Python Library     Python Tuples     Python Dictionary     Python Sets     Python Strings     Python Exception Handling     Python Data File Handling

Visitor Counter

0051048