Python Program
Python Program
Q4.*
**
***
****
*****
# Function to demonstrate printing pattern
def pypart(n):
# Driver Code
n = 5
pypart(n)
Q5. 12345
1234
123
12
1
def num(a):
Q6. A
AB
ABC
ABCD
ABCDE
n = int(input("Enter number of rows: "))
for i in range(1,n+1):
a = 97
for j in range(1, i+1):
print("%c" %(a), end="")
a += 1
print()
Q11Write a python program to determine given number is perfect,an armstrong or palindrome number.
n = int(input("Enter any number to check whether it is perfect ,armstrong or palindrome : "))
sum = 0
# Check for perfect number
for i in range(1,n):
if n%i==0:
sum = sum + i
if sum == n :
print( n,"is perfect number")
else :
print( n, "is not perfect number")
#check for armstrong number
temp = n
total = 0
while temp > 0 :
digit = temp %10
total = total + (digit**3)
temp = temp//10
if n == total:
print( n,"is an armstrong number")
else :
print( n, "is not armstrong number")
#check for palindrome number
temp = n
rev = 0
while n > 0:
d = n % 10
rev = rev *10 + d
n = n//10
if temp == rev :
print( temp,"is palindrome number")
else :
print( temp, "is not palindrome number")
n = int(input("Enter any number to check whether it is perfect number or not : "))
sum = 0
# Check for perfect number
for i in range(1,n):
if n%i==0:
sum = sum + i
if sum == n :
print( n,"is perfect number")
else :
print( n, "is not perfect number")
#check for armstrong number
n = int(input("Enter any number to check whether it is an armstrong : "))
temp = n
total = 0
while temp > 0 :
digit = temp %10
total = total + (digit**3)
temp = temp//10
if n == total:
print( n,"is an armstrong number")
else :
print( n, "is not armstrong number")
Q12 write a program in python to check if the input number is prime or composite number
Q16. write a python program to input a string and determine whether it is a palindrome or
not, convert the case of characters in a string
# Program to check if a string is palindrome or not
my_str = 'aIbohPhoBiA'
s=len(val)
if s%2!=0:
s=s-1
for i in range(0,s,2):
val[i],val[i+1]=val[i+1],val[i]
print("List after swapping :",val)
Q19. input a list/tuple of elements, search for a given element in the list/tuple.
mylist = []
print("Enter 5 elements for the list: ")
for i in range(5):
value = int(input())
mylist.append(value)
print("Enter an element to be search: ")
element = int(input())
for i in range(5):
if element == mylist[i]:
print("\nElement found at Index:", i)
print("Element found at Position:", i+1)
Q20. write a program in python to create a dictionary with the roll number,name and marks of n students in a class
and display the name of students who have marks above 75.