Python for loop

For Loop With Strings

Questions: 17
Write a python script to take input for string and display it in given format
Sol:

n=input("Enter any string ")
for i in n:
    print(i)
    

Output:

Enter any string hello
h
e
l
l
o
>>>

Enter any string computer
c
o
m
p
u
t
e
r
>>>

Question:18
Write a python script to take input for a string, print the string in the given format and also print length of the string?
Sol:

n=input("Enter any string ")
leng=0
for i in n:
    print(i)
    leng=leng+1
print("total length = ",leng)

Output:

Enter any string hello
h
e
l
l
o
total length = 5
>>>

Enter any string hello hi
h
e
l
l
o

h
i
total length = 8
>>>

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

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

Output:

Enter any string hello123hi
h
e
l
l
o
1
2
3
h
i
total alphabets = 7
>>>

Enter any string abc 123 xyz
a
b
c

1
2
3

x
y
z
total alphabets = 6
>>>

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

n=input("Enter any string ")
low=0
for i in n:
    print(i)
    if(i>='a' and i<='z'):
        low=low+1
print("total lower case alphabets = ",low)

Output:

Enter any string HeLLo
H
e
L
L
o
total lower case alphabets = 2
>>>

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