Cs Journal Final
Cs Journal Final
Computer Science-083
CBSE Class - XI
Academic Year 2024-2025
Computer Science-083
CBSE Class XI
Academic Year 2024-25
1
10 Write a program that should do the following: 16
1)Prompt the user for a string
2)Extract all the digits from the string
3)If there are digits: Sum the collected digits together
Print out:
1)The original string
2)The digits
3)The sum of digits
4)If there are no digits:
Print the original string and a message “has no digits”.
12 Write a program that takes two strings from the user and 18
displays the smaller string line and larger string line as per
this format:
1st letter last letter
2nd letter 2nd letter
3rd letter 3rd last letter
2
16 Write a program to input a list of numbers and swap 23
elements at the even location with the elements at the odd
location.
22 Given a nested tuple tup1 = ((1,2), (3, 4.15, 5.15), (7, 8, 12, 29
15)). Write a program that displays the means of individual
elements of tuple tup1 and then displays the mean of these
computed means.
24 Given a tuple pair = ((2,5), (4,2), (9,8), (12, 10)). Count the 31
number of pairs (a, b) such that both a and b are even.
3
26 Create a dictionary with the roll number, name and marks 33
of n students in a class and display the names of students
who have scored marks above 75.
4
d) Modify the phone number of an existing
friend.
e) Check if a friend is present in the dictionary
or not.
f) Display the dictionary in sorted order of
names.
5
1.Write a Program to calculate simple interest and compound interest.
print("Simple Interest:",simple_interest)
print("Compound Interest:",compound_interest)
6
2.WAP to swap two variables using a third variable.
a = int(input("Enter a number:"))
b = int(input("Enter a number:"))
print("Original values:")
print("a =", a)
print("b =", b)
c=a
a=b
b=c
print("\nSwapped values:")
print("a =", a)
print("b =", b)
7
3.WAP to generate 6 random secure OTP between 100000 and 999999.
import random
otp = random.randrange(100000, 999999);
print("OTP:", otp);
8
4.WAP that asks a user for a number of years, and then prints out the number of days,
hours, minutes and seconds in that number of years.
9
5. Write a python to find the sum of the following series:
10
6. Write a program to reverse (3-digit) number.
11
7. A year is a leap year if it is divisible by 4, except that years divisible by 100 are not
leap years unless they are also divisible by 400. Write a program that asks the user
for a year and print out whether it is a leap year or not.
year=int(input("Enter a year:"))
if year%4==0 and (year%100!=0 or year%400==0):
print(year,"is a leap year.")
else:
print(year,"is not a leap year.")
12
8. WAP to print the following pattern:
A
AB
ABC
ABCD
ABCDE
n=5
for i in range(1, n + 1):
for j in range(1, i + 1):
print(chr(64 + j), end=" ")
print()
13
9. WAP to print the following pattern:
n=3
for i in range(1, n+1) :
for j in range(n, i, -1) :
print(' ', end = '')
x=1
while x < 2 * i :
if x == 1 or x == 2 * i - 1 :
print('*', end = '')
else :
print(' ', end = '')
x += 1
print()
for i in range(n-1, 0, -1) :
for j in range(n, i, -1) :
print(' ', end = '')
x=1
while x < 2 * i :
if x == 1 or x == 2 * i - 1 :
print('*', end = '')
else :
print(' ', end = '')
14
x += 1
print()
15
10. Write a program that should do the following:
1)Prompt the user for a string
2)Extract all the digits from the string
3)If there are digits: Sum the collected digits together
Print out:
1) The original string
2) The digits
3) The sum of digits
4)If there are no digits:
Print the original string and a message “has no digits”.
16
11. WAP that does the following:
1) Takes two inputs: the first integer and the second string
2) From the input string extract all the digits, in the order they occurred in
the string.
If no digits occur, set the extracted digits to 0.
3) Add the integer input and the digits extracted from the string together as
integers.
4) Print a statement like:
“Integer_Input + string_digits = Sum”
a=int(input("Enter a number:"))
b=str(input("Enter a string:"))
i=0
sum=0
str_len=len(b)
for i in range (1,str_len):
if b[i].isdigit()==True:
print("Digit",i,":",b[i])
sum=sum+int(b[i])
print("Sum=",sum)
print("Integer input + String Digits=",a+sum)
17
12. WAP that takes two strings from the user and displays the smaller string line and
larger string line as per this format:
1st letter last letter
2nd letter 2nd last letter
3rd letter 3rd last letter
18
13. Write a program to convert a given number into equivalent Roman number (store
its value as a string). You can use following guidelines to develop solution for it:
1)From the given number, pick successive digits, using %10 and /10 to gather the
digits from right to left.
2)The rules for Roman Numerals involve using four pairs of symbols for ones and
five, tens and fifties, hundreds and five hundreds. An additional symbol for thousands
covers all the relevant bases.
3)When a number is followed by the same or smaller number, it means addition. "II"
is two 1's = 2. "VI" is 5 + 1 = 6.
4)When one number is followed by a larger number, it means subtraction. "IX" is 1
before 10 = 9. "IIX isn't allowed, this would be "VIII". For numbers from 1 to 9, the
symbols are "I" and "V", and the coding works like this. "I" , "II", "III", "IV", "V", "VI",
"VII", "VIII", "IX".
5)The same rules work for numbers from 10 to 90, using "X" and "L". For numbers
from 100 to 900, using the symbols "C" and "D". For numbers between 1000 and 4000,
using "M".
19
14. WAP to read a line and prints its statistics like:
1) No. of Lowercase Letters
2) No. of Symbols
3) No. of Digits
4) No. of Alphabets
20
Screenshot of the output:
21
15. WAP that reads an integer and check whether it is palindrome or not.
n=int(input("Enter number:"))
a=n
rev_num=0
while(n>0):
dig=n%10
rev=rev*10+dig
n=n//10
if(a==rev):
print("The number is a palindrome")
else:
print("The number is not a palindrome")
22
16. WAP to input a list of numbers and swap elements at the even location with the
elements at the odd location.
23
17. Input a list of strings. Create a new list that consists of those strings with their
first characters removed.
24
18. Write a program that reads the n to display nth term of Fibonacci series.
n = int(input("Enter n: "))
if (n > 20):
print("n should be less than or equal to 20")
else :
a=0
b=1
c=a+b
for i in range(3, n + 1):
a=b
b=c
c=a+b
print(n, "term of Fibonacci series =", c)
25
19. Write a program to move all duplicate values in a list to the end of the list.
26
20. Write a program that rotates the elements of a list so that element at the first
index moves to the second index, the element in the second index moves to the third
and element at the last index moves to the first index.
27
21. Input a list of numbers to find largest element in a tuple.
28
22. Given a nested tuple tup1 = ((1,2), (3, 4.15, 5.15), (7, 8, 12, 15)). Write a program
that displays the means of individual elements of tuple tup1 and then displays the
mean of these computed means.
29
23. Create the following tuple using a for loop:
a. A tuple consisting of the integers 0 through 49.
b. A tuple containing the squares of the integers 1 through 50.
c. The tuple [‘a’, ‘bb’, ‘ccc’, ‘dddd,’…..] that ends with 26 copies of the letter z.
a. l = []
for i in range(50):
l.append(i)
print("List with integers from 0 to 49:")
print(l)
b. l = []
for i in range(1, 51):
l.append(i * i)
print("List with square of integers from 1 to 50:")
print(l)
c. l = []
for i in range(1, 27):
l.append(chr(i + 96) * i)
print("Created List:")
print(l)
30
24. Given a tuple pair = ((2,5), (4,2), (9,8), (12, 10)). Count the number of pairs (a, b)
such that both a and b are even.
tup = ((2,5),(4,2),(9,8),(12,10))
count = 0
tup_length = len(tup)
for i in range (tup_length):
if tup [i][0] % 2 == 0 and tup[i][1] % 2 == 0:
count = count + 1
print("The number of pair where both a and b are even:", count)
31
25. Write a program to check if the minimum element of a tuple lies at the middle
position of the tuple.
32
26. 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.
33
27. Program to find the highest 2 values in a dictionary.
34
28. Create a dictionary whose keys are month names and whose values are the
number of days in the corresponding months.
a. Ask the user to enter a month name and use the dictionary to tell how many
days are in a month.
b. Print out all the keys in alphabetical order.
c. Print out all the months with 31 days.
d. Print out the (key-value) pairs sorted by the number of days in each month.
days_in_months = {
"january":31,
"february":28,
"march":31,
"april":30,
"may":31,
"june":30,
"july":31,
"august":31,
"september":30,
"october":31,
"november":30,
"december":31
}
m = input("Enter name of month: ")
if m not in days_in_months:
print("Please enter the correct month")
else:
print("There are", days_in_months[m], "days in", m)
print("Months in alphabetical order are:", sorted(days_in_months))
print("Months with 31 days:", end=" ")
35
for i in days_in_months:
if days_in_months[i] == 31:
print(i, end=" ")
day_month_lst = []
for i in days_in_months:
day_month_lst.append([days_in_months[i], i])
day_month_lst.sort()
month_day_lst =[]
for i in day_month_lst:
month_day_lst.append([i[1], i[0]])
sorted_days_in_months = dict(month_day_lst)
print()
print("Months sorted by days:", sorted_days_in_months)
36
29. Write a program to read a sentence and then create a dictionary contains the
frequency of letters and digits in the sentence.
37
30. Write a program that lists the overlapping keys of the two dictionaries. i.e., if a key
of D1 is also a key of D2, then list the keys.
38
31. Create a dictionary with single letter keys, each followed by a 2-element tuple
representing the coordinates of a point in an x-y coordinate plane. Write a program to
print the maximum value from within all of the value’s tuples at same index.
points = {
'A': (2, 3),
'B': (5, 1),
'C': (4, 7),
'D': (6, 2)
}
max_x = max([point[0] for point in points.values()])
max_y = max([point[1] for point in points.values()])
print("Maximum value at index 0 (x):", max_x)
print("Maximum value at index 1 (y):", max_y)
39
32. Write a program to input your friend’s names and their Phone numbers and store
them in the dictionary as the key-value pair. Perform the following operations on the
dictionary.
a. Display the name and phone number of all your friends.
b. Add a new key-value pair in this dictionary and display the modified
dictionary.
c. Delete a particular friend from the dictionary.
d. Modify the phone number of an existing friend.
e. Check if a friend is present in the dictionary or not.
f. Display the dictionary in sorted order of names.
phonebook = {}
num_friends = int(input("Enter how many friends: "))
for i in range(num_friends):
name = input("Enter name of friend: ")
phone = input("Enter phone number: ")
phonebook[name] = phone
40
c. del_name = input("\nEnter name of friend to delete: ")
if del_name in phonebook:
del phonebook[del_name]
print(del_name + " has been deleted.")
else:
print(del_name + " not found.")
print(phonebook)
41
print(key, ":", phonebook[key], end = " ")
print("}")
42