CS winter break solution (1)[1]
CS winter break solution (1)[1]
School
Practical File
Submitted To: Mrs. Amoli (PGT Comp. Sci.)
Submitted By: Shikhar Kumar XI-A
Class Teacher: Mr. Pankaj Kunzru
Table Of Contents
1. Acknowledgement
2. List of Problems
3. Problems
i) Problem 1
ii) Problem 2
iii) Problem 3
iv) Problem 4
v) Problem 5
vi) Problem 6
vii) Problem 7
viii) Problem 8
ix) Problem 9
x) Problem 10
xi) Problem 11
xii) Problem 12
xiii) Problem 13
xiv) Problem 14
xv) Problem 15
xvi) Problem 16
xvii) Problem 17
xviii) Problem 18
xix) Problem 19
xx) Problem 20
xxi) Problem 21
xxii) Problem 22
Acknowledgement
I, Shikhar Kumar, would like to express my sincere gratitude to Mrs.
Amoli Chakroborty for the guidance and support provided throughout the
completion of my Computer Science practical file. Your valuable
feedback and encouragement have been instrumental in shaping my
understanding and skills in the field.
I would also like to extend my appreciation to Mrs. JK Sawhney, our
esteemed School Principal, for fostering an environment that encourages
academic excellence and creativity
This practical file has been a significant learning experience for me, and I
am thankful for the opportunity to explore and apply the concepts learned
in the classroom. I believe that this practical file has not only enriched my
understanding of Computer Science but has also honed my problem-
solving and critical thinking abilities.
Once again, thank you, Mrs. Amoli Chakroborty, for your unwavering
support, and thank you, Mrs. JK Sawhney, for providing a platform for
students to excel and showcase their talents.
Sincerely,
Shikhar Kumar
List of Problems
1. Input a welcome message and display it.
2. Input two numbers and display the larger / smaller number.
3. Input three numbers and display the largest / smallest number.
4. Write a program to accept three numbers and print their sum.
5. Write a program to accept the length and breadth of a rectangle and
calculate its area.
6. Generate the following patterns using nested loop:
(i) *
**
***
****
*****
(ii) 12345
1234
123
12
1
(iii) A
AB
ABC
ABCD
ABCDE
7. Write a program to input the value of x and n and print the sum of the
following series:
(i) 1+x+x2+x3+x4+……..+xn
(ii) 1-x+x2-x3+x4-……..+xn
(iii) x-x2/2+x3/3-x4/4+……..+xn/n
(iv) x+x2/2!+x3/3!+x4/4!+……..+xn/n!
8. Determine whether a given number is a perfect number or not.
9. Determine whether a given number is Armstrong number or not.
10. Determine whether a given number is palindrome or not.
11. Input a number and check whether it is prime or composite.
12. Display the first n terms of the Fibonacci series where n is entered
by the user.
13. Compute the greatest common divisor and least common multiple
of two integers.
14. Count and display the number of vowels,consonants,uppercase and
lowercase characters in a string.
15. Input a string and state whether it is palindrome or not.
16. Input a string and convert the case of characters in the string.
17. Write a program to enter a number and print its reverse.
18. Find the largest/smallest number in a list/tuple.
19. Input a list of numbers and swap elements at the even location with
the elements at the odd location.
20. Input a list/tuple of elements, search for a given element in the
list/tuple.
21. Input a list of numbers and find the smallest and largest number
from the list.
22. 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.
Solutions
Q-1) Input a welcome message and display it.
Ans :
print("Hello, ",message)
Q-2) Input two numbers and display the larger / smaller number.
Ans :
if (n1>n2):
else:
Ans :
Q-4) Write a program to accept three numbers and print their sum.
Ans :
num1=int(input("Enter Number 1 :
")) num2=int(input("Enter Number
2 : ")) num3=int(input("Enter
Number 3 : "))
sum=num1+num2+num3
Q-5) Write a program to accept the length and breadth of a rectangle and calculate its area.
Ans :
length=float(input("Enter the length of rectangle : "))
breadth=float(input("Enter the breadth of rectangle : "))
area=length*breadth
loop: (i)
**
***
****
*****
Ans :
for i in range(1,6):
for j in range(i):
print('*',end=' ')
print( )
(ii)
12345
1234
123
12
1
Ans :
for i in range(6,0,-1):
for j in
range(1,i):
print(j,end= ‘ ‘)
print ( )
(iii)
A
AB
AB
C
ABCD
ABCDE
Ans :
n=5
for i in range(n):
p=65
for j in range(i+1):
print(chr(p),end= ' ')
p+=1
print()
Q-7 Write a program to input the value of x and n and print the sum of the following series:
(i) 1+x+x2+x3+x4+…......+xn
Ans :
x = float(input("Enter x: "))
n = int(input("Enter n: "))
result1 = 0
power1 = 1
result1 += power1
power1 *= x
n = int(input("Enter n: "))
result2 = 0
power2 = 1
power2 *= x
(iii) x-x2/2+x3/3-x4/4+…......+xn/n
Ans :
x = float(input("Enter x: "))
n = int(input("Enter n: "))
result3 = 0
power3 = 1
for i in range(1, n + 1):
result3 += power3 / i * ((-1) ** (i - 1))
power3 *= x
print("Series (iii) sum:", result3)
(iv) x+x2/2!+x3/3!+x4/4!+…......+xn/n!
Ans :
x = float(input("Enter x: "))
n = int(input("Enter n: "))
result4 = 0
power4 = 1
for i in range(1, n + 1):
fact = 1
for j in range(1, i + 1):
fact *= j
result4 += power4 /
fact power4 *= x
print("Series (iv) sum:", result4)
Q-13 Compute the greatest common divisor and least common multiple of two
integers. Ans :
num1 = int(input("Enter first number: "))
num2 = int(input("Enter second number: "))
a, b = num1, num2
while b:
a, b = b, a % b
gcd_result = a
lcm_result = abs(num1 * num2) // gcd_result
print("GCD:", gcd_result)
print("LCM:", lcm_result)
print("Vowels:", vowels)
print("Consonants:", consonants)
print("Uppercase:", uppercase)
print("Lowercase:", lowercase)
Q-19 Input a list of numbers and swap elements at the even location with the
elements at the odd location.
Ans :
val=eval(input("Enter a list "))
print("Original List is:",val)
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)
Q-20 Input a list/tuple of elements, search for a given element in the
list/tuple. Ans :
elements = tuple(input("Enter elements separated by space: ").split())
search_element = input("Enter element to search: ")
if search_element in elements:
print(search_element, "is present in the tuple.")
else:
print(search_element, "is not present in the tuple.")
Q-21 Input a list of numbers and find the smallest and largest number from the
list. Ans :
values = input("Enter numbers separated by space: ")
numbers = values.split()
if numbers:
smallest = largest =
int(numbers[0]) for num in
numbers[1:]:
num = int(num)
if num < smallest:
smallest =
num
elif num >
largest:
largest = num
print("Smallest number:", smallest)
print("Largest number:", largest)
else:
print("No numbers entered.")
Q-22 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.
Ans :
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)
for student in result:
if result[student][1] > 75:
print("Students who got more than 75 marks are",(result[student][0]))