xi practical file
xi practical file
Output:
Enter your name :KV Chhatarpur
Welcome in the world of Python : KV Chhatarpur
#Pattern-1
for i in range(1,6):
for j in range(i):
print('*',end='')
print()
Output: *
**
***
****
*****
#Pattern-2
for i in range(5):
for j in range(1,6-i):
print(j,end='')
print()
Output: 12345
1234
123
12
1
#Pattern-3
for i in range(1,6):
for j in range(65,65+i):
a = chr(j)
print(a,end='')
print()
Output: A
AB
ABC
ABCD
ABCDE
5.#Write a program to input the value of x and n, and print
the sum of the
#series 1+x+x^2+x^3+x^4.....+x^n
x=float(input("Enter the value of x "))
n=int(input("Enter the value of n "))
sum=0
for e in range(n+1):
sum=sum+x**e
print("The sum of the series",s)
Output:
Enter the value of x 2
Enter the value of n 4
The sum of the series 31.0
Output:
Enter the value of x 2
Enter the value of n 4
The sum of the series 11.0
7.#Write a program to input the value of x and n, and print
the sum of the
#series x-x^2/2+x^3/3-x^4/4.....+x^n
x=float(input("Enter the value of x "))
n=int(input("Enter the value of n "))
sum_even=0
sum_odd=0
for e in range(1,n+1):
if e%2==0:
sum_even=sum_even+(x**e)/e
else:
sum_odd=sum_odd+(x**e)/e
print("The sum of the series",sum_odd-sum_even)
Output:
Enter the value of x 2
Enter the value of n 5
The sum of the series 5.066666666666666
Output:
Enter an integer number153
The number 153 is armstrong number
while n1>0:
rem=n1%10
rev=rev*10+rem
n1=n1//10 #n//=10
if n2=rev:
print("The number",n2," is pelendrom")
else:
print("The number",n2," is not pelendrom")
Output:
Enter an integer: 232
The number 232 is pelendrom
12.#Input a number and check if the number is a prime or
composite number.
num = int(input("Enter an integer number"))
if num > 1:
for i in range(2,num//2+1):
if (num % i) == 0:
print(num, "is composite prime number")
break
else:
print(num, "is a prime number")
else:
print(num, "is not a number")
Output:
Enter an integer number17
17 is a prime number
Output:
Enter any string :malayalam
string is palindrome
Output:
Enter a list: [1,5,7,10,23,77]
The Updated List is: [11, 15, 17, 20, 33, 87]
18. #Write a program in Python to change the item to its
next item such as first with second, third with fourth and
so on ListA = [1, 5, 7, 10, 15, 23]
Then after change, ListA = [5, 1, 10, 7, 23, 15]
a=eval(input("Enter any list: "))
L=len(a)
if L%2==0:
pass
else:
L=L-1
for i in range(0,L,2):
b=a[i]
c=a[i+1]
a[i]=c
a[i+1]=b
print("List after swapping adjacent Ele: ",a)
Output:
Enter any list[1, 5, 7, 10, 15, 23]
List after swapping adjacent Ele [5, 1, 10, 7, 23, 15]
Output:
Enter a list: [2, 5, 7, 10, 15, 23]
Max : 23 Min : 2
Output:
Enter a list :['AP', 'MP', 'UP', 'CG']
Enter the element to be searched: AP
AP and location is 0
22. #Write a program in Python to create the following Tuple
and print the smallest and largest value item in the
TupleAge as
TupleAge = (2, 5, 7, 10, 15, 23)
Max : 23 Min 2
Output:
Enter age of persons: (2, 5, 7, 10, 15, 23)
Max age: 23 Min age: 2
Output:
Enter age of persons: ("Gyanesh", "Akash", "Pradeep",
"Brijendra")
['Akash', 'Brijendra', 'Gyanesh', 'Pradeep']
23. #Write a Python program to create a tuple
RateTuple = (50, 15, 2, 35, 40) and
print the Highest Rate, Lowest Rate and Total Amount.
Output:
Enter rates of item: (50, 15, 2, 35, 40)
Highest Rate: 50
Lowest Rate: 2
Total Amount: 142
date=input("Enter date:")
months = {1:'January', 2:'February', 3:'March',\ 4:'April',
5:'May', 6:'June', 7:'July', 8:'August',\ 9:'September',
10:'October',11:'November',12:'December'}
mon = months[int(date[:2])]
day = date[2:4]
year = date[4:]
fdate = mon + ' ' + day + ',' + year
print(fdate)
Output:
Enter date:11272020
November 27,2020
25. #Write a program to create a Dictionary name DYear and
save the items with month name as Keys and number of Days in
the month as Value. Then month name and number of days as
output.
Output:
Enter the name of the month: January
There are 31 days in January