word=input("enter word") x="" for i in word: x+=i print(x) Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter word pythonprogram p py pyt pyth pytho python pythonp pythonpr pythonpro pythonprog pythonprogr pythonprogra pythonprogram
Q2.Program pattern of character.
asciinumber=65 r=int(input("enter rows")) for i in range(0,r): for j in range(0,i+1): ch=chr(asciinumber) print(ch, end=' ') asciinumber=asciinumber+1 print(" ") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter rows5 A B C D E F G H I J K L M N O >>>
Q3.Program inverted half pyramid.
r=int(input("enter row")) for i in range(r,0,-1): for j in range(0,i): print("*", end=' ') print("\r") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter row5 * * * * * * * * * * * * * * *
Q4.Program to print triangle pattern.
r=int(input("enter row")) for i in range(r): for s in range(-(r+1),-i): print(" ",end="") for j in range(i+1): print("*",end=" ") print() Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter row5 * * * * * * * * * * * * * * *
Q5.Program to print same digit pattern.
n=int(input("enter digit")) for i in range(n,0,-1): for j in range(0,i): print(n,end=' ') print("\r") Output >>> ==================== RESTART: C:/Users/Dell/Desktop/ss.py ==================== enter digit6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
0 Comments