0% found this document useful (0 votes)
943 views

XI CS Practical File 2022-23

The document contains the practical record file of Class XI Science students of Kendriya Vidyalaya Chhatarpur for the academic year 2022-23. It includes 22 programming problems and their solutions/outputs covering topics like input/output, if-else conditions, loops, functions, strings, lists, tuples etc. Each problem has the Python code to solve it along with sample input/output. The file is organized with the problem number, description and solution to help students practice and learn Python programming concepts.

Uploaded by

Tushar Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
943 views

XI CS Practical File 2022-23

The document contains the practical record file of Class XI Science students of Kendriya Vidyalaya Chhatarpur for the academic year 2022-23. It includes 22 programming problems and their solutions/outputs covering topics like input/output, if-else conditions, loops, functions, strings, lists, tuples etc. Each problem has the Python code to solve it along with sample input/output. The file is organized with the problem number, description and solution to help students practice and learn Python programming concepts.

Uploaded by

Tushar Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

KENDRIYA VIDYALAYA cHHATARPUR

Practical record file


SESSION:2022-2223

CLASS:XI SCIENCE
TABLE OF CONTENTS
Sr. Topic Page No. Sign
No.
XI_CS_Practical_File

1.#Input a welcome message and display it


name=input("Enter your name :")
print("Welcome in the world of Python :",name)

Output:
Enter your name :KV Chhatarpur
Welcome in the world of Python : KV Chhatarpur

2.Input two numbers and print larger and smaller number


n1=int(input("Enter first number :"))
n2=int(input("Enter second number :"))
if n1>n2:
print("The larger number is :",n1,"and the smaller
is :",n2)
elif n1==n2:
print("Both",n1,'and',n2,'are equal')
else:
print("The larger number is :",n2,"and the smaller
is :",n1)
Output:
Enter first number :10
Enter second number :20
The larger number is : 20 and the smaller is : 10
3. #Input three number and display Largest/Smallest and
number
a=int(input("Enter first number: "))
b=int(input("Enter second number: "))
c=int(input("Enter third number: "))
max,middle,small=0,0,0
if a>=b and a>=c:
max=a
if b>c:
middle=b
small=c
else:
middle=c
small=b
if b>=c and b>=a:
max=b
if a>c:
middle=a
small=c
else:
middle=c
small=a
if c>=b and c>=a:
max=c
if a>b:
middle=a
small=b
else:
middle=b
small=a
print("Largest no=",max,"Middle no=",middle,"Smallest
no=","Smalest no=",small)
Output:
Enter first number: 10
Enter second number: 20
Enter third number: 30
Largest no= 30 Middle no= 20 Smallest no= 10
4.Generate the following pattern

#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

6. #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_even=0
sum_odd=0
for e in range(n+1):
if e%2==0:
sum_even=sum_even+x**e
else:
sum_odd=sum_odd+x**e
print("The sum of the series",sum_even-sum_odd)

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

8.#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/n!
x = int(input("Enter the value of x: "))
n=int(input("Enter the value of n : "))
sum = 0
m = 1
for i in range(1, n+1) :
fact = 1
for j in range(1, i+1) :
fact *= j
term = x ** i / fact
sum =sum+ term * m
m = m * -1
print("Sum =", sum)
Output:
Enter the value of x: 2
Enter the value of n 4
Sum = 0.6666666666666666
9.#Determine whether a number is a perfect number
n=int(input("Enter a number :"))
sum = 1
# Find all divisors and add them
i = 2
while i * i <= n:
if n % i == 0:
sum = sum + i + n/i
i += 1
if sum == n and n!=1 :
print("Number ",n,"is a perfect number")
else:
print("Number ",n,"is not a perfect number")
Output:
Enter a number 15
Number 15 is not a perfect number
10. #Determine whether a number is a armstrong number
n=int(input("Enter an integer number "))
sum=0
num=n
while n>0:
digit=n%10
n=n//10
sum=sum+digit**3
if num==sum:
print("The number",num,"is armstrong number ")

Output:
Enter an integer number153
The number 153 is armstrong number

11.#Determine whether a number is a palindrome number


n1=int(input("Enter an integer"))
rev=0
n2=n1

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

13.#Display the terms of a Fibonacci series.


term=int(input("How many terms?"))
a,b=0,1
count=0
if term<=0:
print("Please Enter a positive integer")
elif term==1:
print("Fibonacci sequence upto ", terms," :",end='')
print(a)
else:
print("Fibonacci sequence :" ,end='')
for i in range(term):
print(a,end='\t')
c=a+b
a=b
b=c
Output:
How many terms? 8
Fibonacci sequence :0 1 1 2 3 5 8 13
14.#Compute the greatest common divisor and # the least
common multiple of two integers.
x=int(input("Enter first number :"))
y=int(input("Enter Second number: "))
if x > y:
smaller = y
else:
smaller = x
for i in range(1, smaller+1):
if((x % i == 0) and (y % i == 0)):
gcd = i

print('GCD of', x ,'and' ,y ,'is',gcd)


lcm=x*y/gcd
print('LCM of', x ,'and' ,y ,'is',lcm)
Output: Enter first number :12
Enter Second number: 18
GCD of 12 and 18 is 6
LCM of 12 and 18 is 36.0

15. #Count and display the number of vowels,


#consonants, uppercase, lowercase characters in string.
str1=input("Enter any string: ")
v,u,l,w,c=0,0,0,0,0
for ch in str1:
if ch.islower():
l=l+1
if ch.isupper():
u=u+1
if ch.lower() in ['a','e','i','o','u']:
v=v+1
elif ch.isalpha():
c=c+1
print('Total number of Uppercase letters :',u)
print('Total number of Lowercase letters :',l)
print('Total number of Vowel :',v)
print('Total number of consonant :',c)
Output:
Enter any string: AEioudef
Total number of Uppercase letters : 2
Total number of Lowercase letters : 6
Total number of Vowel : 6
Total number of consonant : 2

16. #Input a string and determine whether it is a palindrome


or not;#convert the case of characters in a string.
str1=input("Enter any string :")
for i in range(0,int(len(str1)/2)):
if str1[i]!=str1[len(str1)-i-1] :
print('string is not pelendrom')
break
else:
print("string is palindrome")

Output:
Enter any string :malayalam
string is palindrome

17. #Write a program in Python to create the following list


and add 10 to each item in the list.
ListA = [1, 5, 7, 10, 15, 23, 77]
then after change, ListA = [11, 15, 17, 21, 33, 87]

ListA=eval(input("Enter a list: "))


for i in range(len(ListA)):
ListA[i]+=10
print("The Updated List is: ",ListA)

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]

19. #Write a program in Python to create the following list


and convert the even elements to its half and odd elements
to double. ListA = [1, 5, 7, 10, 15, 23]

ListA=eval(input("Enter a list: "))


for i in range(len(ListA)):
if ListA[i] %2 ==0:
ListA[i] /= 2
else:
ListA[i] *= 2
print("The Updated List is: ",ListA)
Output:
Enter a list: [1,5,7,10,15,23]
The Updated List is: [2, 10, 14, 5.0, 30, 46]
20. # Write a program in Python to create the following list
and print the smallest and largest value item in the listA.
ListA = [2, 5, 7, 10, 15, 23] Max : 23 Min 2

ListA=eval(input("Enter a list: "))


ListA.sort()
print("Max :",ListA[len(ListA)-1],"Min :",ListA[0])

Output:
Enter a list: [2, 5, 7, 10, 15, 23]
Max : 23 Min : 2

21. # Write a program in Python to search for an item in the


existing ListB ListB = [“AP”, “MP”, “UP”, “CG”]
Item Search : CG and Location is 2
ListA=eval(input("Enter a list"))
e=input("Enter the element to be searched: ")
found=False
for i in range(len(ListA)):
if ListA[i]==e:
found=True
print(e," and location is ",ListA.index(e))
if found==False:
print(" Element not found ")

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

tup=eval(input('Enter age of persons: '))


print('Max age:',max(tup),'Min age: ',min(tup))

Output:
Enter age of persons: (2, 5, 7, 10, 15, 23)
Max age: 23 Min age: 2

22. #Write a Python program to create a tuple


EmpT = ("Gyanesh", "Akash", "Pradeep", "Brijendra") and
print the elements in Ascending order as
['Akash', 'Brijendra', 'Gyanesh', 'Pradeep']

EmpT=eval(input('Enter age of persons: '))


EmpL=list(EmpT)
EmpL.sort()
print(EmpL)

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.

RateTuple=eval(input('Enter rates of item: '))


print("Highest Rate:",max(RateTuple))
print("Lowest Rate:",min(RateTuple))
print("Total Amount:",sum(RateTuple))

Output:
Enter rates of item: (50, 15, 2, 35, 40)
Highest Rate: 50
Lowest Rate: 2
Total Amount: 142

24. #Write a program to input a date as an integer in the


format MMDDYYYY. The program should print out the date in
the format ,
Example: Input - 11272020 Output - November 27, 2020

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.

d = {"January":31, "February":28, "March":31,\


"April":30, "May":31, "June":30, "July":31,\
"August":31, "September":30, "October":31,\
"November":30, "December":31}
a = input("Enter the name of the month: ")
for i in d.keys():
if i==a:
print("There are ",d[i],"days in ",a)

Output:
Enter the name of the month: January
There are 31 days in January

26. #Write code in Python to calculate and display the


frequency of each character in a string using a dictionary.
str1=input("Enter the string")
dict_freq = {}
for i in test_str:
if i in dict_freq:
dict_freq[i] += 1
else:
dict_freq[i] = 1
print("Count of all characters in string is :\n ",dict_freq)
Output:
Enter the string I Love Python
Count of all characters in string is :
{'G': 2, 'e': 4, 'k': 2, 's': 2, 'f': 1, 'o': 1, 'r': 1}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy