0% found this document useful (0 votes)
4 views28 pages

Now Again

This document is a practical file for Computer Science class XI A, authored by Avinash Kumar. It includes a detailed index of programming exercises covering various topics such as input/output operations, number comparisons, pattern generation, and data structures in Python. Each practical exercise is followed by sample code and output, demonstrating different programming concepts.

Uploaded by

Avinash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views28 pages

Now Again

This document is a practical file for Computer Science class XI A, authored by Avinash Kumar. It includes a detailed index of programming exercises covering various topics such as input/output operations, number comparisons, pattern generation, and data structures in Python. Each practical exercise is followed by sample code and output, demonstrating different programming concepts.

Uploaded by

Avinash
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 28

pg.

1
1

R.P.V.V SEC 19 DWARKA (1821285)

Name: Avinash Kumar


Roll No: 09
Class:XI A

COMPUTER SCIENCE
PRACTICAL FILE
2

INDEX
S.no TOPIC Page No Signature

1. Input a welcome message and display it. 4

2. Input 2 nos and display larger no 5

3. Input 3 nos and display larger no 6

4. Generate patterns using the nested loop 7 - 10

5. Write a program to input the value of X and n 11 - 13

6. input a number and check if the number 14 - 16


is a prime or composite number.

7. Input a number and check if the number 17


is a prime or composite number

8. Display the terms of the fibonacci series 18

9. Compute the greatest common divisor 19 - 20


and least multiple of two integers
3

10. Input a string and determine whether it is 21


a palindrome or not; convert the case of
characters in a string.

11. Find the smallest/largest number in a 22


list/tuple.

S.no TOPIC Page No Signature

12. Input a list of numbers and swap elements 23 - 24


at the even location with the elements at
the odd location Python Program.

13. Input a list/tuple of elements and search 25 - 26


for a given element in the list/tuple Python
Program.

14. Input a list of numbers and find the 27


smallest and largest number from the list
Python Program.

15. Create a dictionary with the roll number,


name and marks of n students in a class 28-29
and display the names of students who
have scored marks above 75.
4

Practical - 1
Q)Input a welcome message and display it.

a=("welcome to python world")


print(a)
[OUTPUT]

[PROGRAM FINISHED]
5

Practical - 2
Q)Input two numbers and display the larger/smaller
number.

a=int(input("enter first number:"))


b=int(input("enter second number:"))
if a>b:
print(a,"is larger")
print(b,"is smaller")
else:
print(b,"is larger")
print(a,"is smaller")
[OUTPUT]

[PROGRAM FINISHED]
6

Practical - 3
Q.Input three numbers and display the largest/smallest
number.

a=int(input("enter first number:"))


b=int(input("enter second number:"))
c=int(input("enter third number:")) if
a>b and a>c: print(a,"is largest
number")
elif b>a and b>c:
print(b,"is largest number")
else:
print(c,"is largest number")3
[ OUTPUT]

[PROGRAM FINISHED]
7

Practical - 4
Q)(a) Generate the following pattern using a nested
loop.

*
**
***
**** ***** n=int(input("enter

number of rows")) for i in

range(0,n):

for j in range(0,i+1):
print("*",end="")
print(" ") [OUTPUT]
8

[PROGRAM FINISHED]
b)12345
1234
123
12
1

for i in range(5,0,-1):
for j in range(1,i+1):
print(j,end="")
print()
9

[OUTPUT]

[PROGRAM FINISHED]
c) A
AB
ABC
ABCD

for i in range(1,6):
A=65
for j in range(0,i):
print(chr(A),end="")
A=A+1
print()

[OUTPUT]
10

[PROGRAM FINISHED]
11

Practical - 5
Q- Write a program to input the value of X and n and
print the sum of the following series:
(a)1+x+x2+x3+x4+................xn

x=int(input("enter x:"))
n=int(input("enter n:"))
s=0 for i in range(n):
s=s+(x**i)
print(s)

[OUTPUT]

[PROGRAM FINISHED]
(b)1-x+x2-x3+x4…….xn.
12

x=int(input("enter"))
n=int(input("enter"))
s=x for i in
range(1,n): z=i+1 if
i%2==0:
s=s+((x**z)/z)
else:
s=s-((x**z)/z)
print(s)

[OUTPUT]

[PROGRAM FINISHED]

(C)x-x2/2+x3/3-x4/4…………..xn

x=int(input("enter"))
n=int(input("enter"))
13

s=x f=1 for i in


range(1,n):
z=i+1
f=f*1 if
i%2==0:
s=s+((x**z)/f)
else:
s=s-((x**z)/f)
print(s)
OUTPUT.

[PROGRAM FINISHED]
14

Practical - 6
Q-Determine whether a number is a perfect number, an
armstrong number or a palindrome.

#palindrome(12321 is palindrome)
number=int(input("enter any number:")) num=number
num1=number rev=0 while num>0: digit=num%10
rev=rev*10+digit num=int(num/10)

if number==rev:
print(number,'is a palindrome')
else:
print(number,'is not a palindrome')
#Armstrong number is equal to sum of cubes of each
digit
sum=0
temp=num1
15

while temp>0:
digit=temp%10
sum+=digit**3
temp//=10
if num1==sum:
print(num1,"is an Armstrong number")
else:
print(num1,"is not a Armstrong number")
#perfect number,a positive integer that is equal to
the sum of its proper divisors. sum1=0 for i in
range(1,number):
if(number%i==0):
sum1=sum1+i
if(sum1==number):
print(number,"the number is a perfect number
number.")
else:
print(number,"the number is not a perfect number.")

[OUTPUT]
16

Practical - 7

Q-Input a number and check if the number is a prime or


composite number.

n=int(input("enter"))
flag=False for i in
range(2,n): if
n%i==0:
flag=True
if flag==True:
print("composite number")
else: print("prime number")

[OUTPUT]
17

[PROGRAM FINISHED]

Practical - 8
Q-Display the terms of the fibonacci series.
n=int(input("enter"))
a=0 b=1
print("",a,b,end="")
for i in range(n):
c=a+b a,b=b,c
print("",c,end=""
)

[OUTPUT]

[PROGRAM FINISHED]
18

Practical - 9
Q) Compute the greatest common divisor and least
multiple of two integers.

num1 = int(input("Enter 1st number: "))


num2 = int(input("Enter 2nd number: "))
i = 1 while(i <= num1 and i <= num2):
if(num1 % i == 0 and num2 % i == 0):
gcd = i
i=i+1
print("Greatest Common Divisor (GCD) is ", gcd)
# LCM PROGRAM
if num1 > num2:
greater = num1
else:
greater = num2
while(True): if((greater %
num1 == 0) and (greater %
num2 ==
19

0)):
lcm = greater
break
greater += 1
print("The Least Common Multiple (LCM) is ", lcm)

[OUTPUT]

[PROGRAM FINISHED]
20

Practical - 10

Q)Input a string and determine whether it is a


palindrome or not; convert the case of characters in a
string.

str=input("Enter a string:")
w="" for element in str[::-
1]: w = w+element if
(str==w):
print(str, 'is a Palindrome string')
else: print(str,' is NOT a Palindrome
string')

[OUTPUT]

[PROGRAM FINISHED]
21

Practical - 11

Q)Find the smallest/largest number in a list/tuple.

# list of numbers list1 = [7,


10, 12, 3, 100, 95]
# sorting the list
list1.sort()
# printing the first element
print("Smallest element is:", list1[:1])

[OUTPUT]

[PROGRAM FINISHED]
22

Practical -12
Q)Input a list of numbers and swap elements at the
even location with the elements at the odd location
Python Program.

# Entering 5 element Lsit mylist = []


print("Enter 5 elements for the list: ")
for i in range(5):
value = int(input())
mylist.append(value) # printing original
list print("The original list : " +
str(mylist)) # Separating odd and even
index elements odd_i = [] even_i = [] for i
in range(0, len(mylist)): if i % 2:
even_i.append(mylist[i])
else : odd_i.append(mylist[i])
result = odd_i + even_i
# print result print("Separated odd and even index list: "
+ str(result))
23

[OUTPUT]

[PROGRAM FINISHED]
24

Practical – 13
Q)Input a list/tuple of elements and search for a given
element in the list/tuple Python Program. mylist = []
print("Enter 5 elements for the list: ") for i in
range(5):
value = int(input())
mylist.append(value)
25

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)
[OUTPUT]

[PROGRAM FINISHED
26

Practical - 14
Q)Input a list of numbers and find the smallest and largest
number from the list Python Program.

#create empty list mylist = [] number = int(input('How


many elements to put in List: ')) for n in range(number):
element = int(input('Enter element '))
mylist.append(element)
print("Maximum element in the list is :", max(mylist))
print("Minimum element in the list is :", min(mylist))

[OUTPUT]

[PROGRAM FINISHED]
27

Practical - 15

Q)Create a dictionary with the roll number, name and marks of


n students in a class and display the names of students who
have scored marks above 75.

no_of_std = int(input("Enter number of students: "))

result = {} for i in range(no_of_std):

print("Enter Details of student No.", i+1)

roll_no = int(input("Roll No: "))

std_name = input("Student Name: ")

marks = int(input("Marks: "))

result[roll_no] = [std_name, marks]

print(result)

# Display names of students who have got marks more than 75

for student in result:


if result[student][1] > 75:
28

print("Student's name who get more than 75 marks


is/are",(result[student][0]))

[OUTPUT]

[PROGRAM FINISHED]

You might also like