0% found this document useful (0 votes)
41 views44 pages

Cs Journal Final

The document is a programming assignment for CBSE Class XI Computer Science, detailing various programming tasks to be completed by a student named Nithik Mahesh Hadwani for the academic year 2024-2025. It includes a list of 32 programming exercises, covering topics such as interest calculation, string manipulation, pattern printing, and data structures like lists and dictionaries. Each task is accompanied by sample code and expected outputs.

Uploaded by

Nithik Hadwani
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)
41 views44 pages

Cs Journal Final

The document is a programming assignment for CBSE Class XI Computer Science, detailing various programming tasks to be completed by a student named Nithik Mahesh Hadwani for the academic year 2024-2025. It includes a list of 32 programming exercises, covering topics such as interest calculation, string manipulation, pattern printing, and data structures like lists and dictionaries. Each task is accompanied by sample code and expected outputs.

Uploaded by

Nithik Hadwani
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/ 44

Singapore

Computer Science-083
CBSE Class - XI
Academic Year 2024-2025

Name: Nithik Mahesh Hadwani


Class: 11-B
Reg. No:
Singapore

Computer Science-083
CBSE Class XI
Academic Year 2024-25

Name: Nithik Hadwani Reg.No:

External Examiner: Teacher in charge: Ms.Ritu Arora


( )
INDEX

S.NO PROGRAM PAGE SIGNATURE


NO.
1 Write a program to calculate simple interest and 6
compound interest.

2 Write a program to swap two variables using a third 7


variable.

3 Write a program to generate 6 random secure OTP 8


between 100000 and 999999.

4 Write a program that asks a user for a number of years, and 9


then prints out the number of days, hours, minutes and
seconds in that number of years.

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 12


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.

8 Write a program to print the following pattern: 13


A
AB
ABC
ABCD
ABCDE

9 WAP to print the following pattern: 14

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”.

11 Write a program that does the following: 17


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”

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

13 Write a program to convert a given number into equivalent 19


Roman number (store its value as a string).

14 Write a program to read a line and prints its statistics like: 20


1) No. of Lowercase Letters
2) No. of Symbols
3) No. of Digits
4) No. of Alphabets

15 Write a program that reads an integer and check whether it 22


is palindrome or not.

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.

17 Input a list of strings. Create a new list that consists of 24


those strings with their first characters removed

18 Write a program that reads the n to display nth term of 25


Fibonacci series.

19 Write a program to move all duplicate values in a list to the 26


end of the list.

20 Write a program that rotates the elements of a list so that 27


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.

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, 29
15)). Write a program that displays the means of individual
elements of tuple tup1 and then displays the mean of these
computed means.

23 1. Create the following tuple using a for loop: 30


 A tuple consisting of the integers 0 through 49.
 A tuple containing the squares of the integers 1
through 50.
 The tuple [‘a’, ‘bb’, ‘ccc’, ‘dddd,’…..] that ends with 26
copies of the letter z

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.

25 Write a program to check if the minimum element of a 32


tuple lies at the middle position of the tuple.

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.

27 Program to find the highest 2 values in a dictionary. 34

28 Create a dictionary whose keys are month names and 35


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.

29 Write a program to read a sentence and then create a 37


dictionary contains the frequency of letters and digits in
the sentence.

30 Write a program that lists the overlapping keys of the two 38


dictionaries. i.e., if a key of D1 is also a key of D2, then list
the keys.

31 Create a dictionary with single letter keys, each followed by 39


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.

32 Write a program to input your friend’s names and their 40


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.

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.

principal = float(input("Enter the principal amount: "))


rate = float(input("Enter the interest rate (%): "))
time = float(input("Enter the time period (years): "))

simple_interest = (principal * rate * time) / 100


compound_interest = principal * ((1 + rate/100) ** time) – principal

print("Simple Interest:",simple_interest)
print("Compound Interest:",compound_interest)

Screenshot of the output:

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)

Screenshot of the output:

7
3.WAP to generate 6 random secure OTP between 100000 and 999999.

import random
otp = random.randrange(100000, 999999);
print("OTP:", otp);

Screenshot of the output:

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.

years=int(input("Enter number of years:"))


days=years*365
hours=days*24
minutes=hours*60
seconds=minutes*60
print ("number of days=",days)
print ("number of hours=",hours)
print ("number of minutes=",minutes)
print ("number of second=",seconds)

Screenshot of the output:

9
5. Write a python to find the sum of the following series:

x = int(input("Enter the value of x: "))


n = int(input("Enter the value of n: "))
sum = 0
for i in range(1, n + 1) :
term = x ** i / i
sum += term
print("The sum of the given series is", sum)

Screenshot of the output:

10
6. Write a program to reverse (3-digit) number.

number = int(input("Enter the integer number: "))


revs_number = 0
while (number > 0):
remainder = number % 10
revs_number = (revs_number * 10) + remainder
number = number // 10
print("The reverse number is :",revs_number)

Screenshot of the output:

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.")

Screenshot of the output:

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()

Screenshot of the output:

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()

Screenshot of the output:

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”.

str = input("Enter the string: ")


sum = 0
digitStr = ''
for ch in str :
if ch.isdigit() :
digitStr += ch
sum += int(ch)
if not digitStr :
print(str, "has no digits")
else :
print(str, "has the digits", digitStr, "which sum to", sum)

Screenshot of the output:

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)

Screenshot of the output:

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

str1 = input("Enter first string: ")


str2 = input("Enter second string: ")
small = str1
large = str2
if len(str1) > len(str2) :
large = str1
small = str2
print(small)
lenLarge = len(large)
for i in range(lenLarge // 2) :
print(' ' * i, large[i], ' ' * (lenLarge - 2 * i), large[lenLarge - i - 1], sep='')

Screenshot of the output:

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".

n = int(input("Enter the number: "))


num = (1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1)
rom = ('M', 'CM', 'D', 'CD','C', 'XC','L','XL','X','IX','V','IV','I')
result = ' '
for i in range(len(num)) :
count = int(n / num[i])
result += str(rom[i] * count)
n -= num[i] * count
print(result)

Screenshot of the output:

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

line = input("Enter a line of text: ")


num_lowercase = 0
num_symbols = 0
num_digits = 0
num_alphabets = 0

for char in line:


if char.islower():
num_lowercase += 1
elif char.isdigit():
num_digits += 1
elif char.isalpha():
num_alphabets += 1
else:
num_symbols += 1

print("Number of lowercase letters:", num_lowercase)


print("Number of symbols: ", num_symbols)
print("Number of digits: ", num_digits)
print("Number of alphabets:", num_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")

Screenshot of the output:

22
16. WAP to input a list of numbers and swap elements at the even location with the
elements at the odd location.

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)

Screenshot of the output:

23
17. Input a list of strings. Create a new list that consists of those strings with their
first characters removed.

l1 = eval(input("Enter a list of strings: "))


l2 = []
for i in range(len(l1)):
l2.append(l1[i][1:])
print("List after removing first characters:")
print(l2)

Screenshot of the output:

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)

Screenshot of the output:

25
19. Write a program to move all duplicate values in a list to the end of the list.

l = eval(input("Enter the list: "))


dedup = []
dup = []
for i in l:
if i in dedup:
dup.append(i)
else:
dedup.append(i)
l = dedup + dup
print("Modified List:")
print(l)

Screenshot of the output:

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.

l = eval(input("Enter the list: "))


print("Original List")
print(l)
l = l[-1:] + l[:-1]
print("Rotated List")
print(l)

Screenshot of the output:

27
21. Input a list of numbers to find largest element in a tuple.

t = (5, 7, 30, 2008, 1)


x=list(t)
x.sort(reverse=True)
max_val=x[0]
print("Maximum value is:", max_val)

Screenshot of the output:

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.

tup1 = ((1, 2), (3, 4.15, 5.15), ( 7, 8, 12, 15))


total_mean = 0
tup1_len = len(tup1)
for i in range(tup1_len):
mean = sum(tup1[i]) / len(tup1[i])
print("Mean element", i + 1, ":", mean)
total_mean = total_mean + mean
print("Mean of means" ,total_mean / tup1_len)

Screenshot of the output:

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)

Screenshot of the output:

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)

Screenshot of the output:

31
25. Write a program to check if the minimum element of a tuple lies at the middle
position of the tuple.

tup = eval(input("Enter a tuple: "))


smallest = min(tup)
middle_index = len(tup) // 2
if tup[middle_index] == smallest:
print("The smallest element is at the middle position.")
else:
print("The smallest element is NOT at the middle position.")

Screenshot if the output:

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.

n = int(input("Enter the number of students: "))


student_data = {}
for i in range(n):
roll_number = int(input("Enter roll number for student: "))
name = input("Enter name for student: ")
marks = int(input("Enter marks for student: "))
student_data[roll_number] = {'name': name, 'marks': marks}
print(student_data)
print("Students who have secured marks above 75:")
for roll_number, details in student_data.items():
if details['marks'] > 75:
print(details['name'])

Screenshot of the output:

33
27. Program to find the highest 2 values in a dictionary.

d = eval(input("Enter the dictionary: "))


s = sorted(d.values())
print("Dictionary:", d)
print("Highest 2 values are:", s[-1], s[-2])

Screenshot of the output:

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)

Screenshot of the output:

36
29. Write a program to read a sentence and then create a dictionary contains the
frequency of letters and digits in the sentence.

sentence = input("Enter a sentence: ")


frequency = {}
for char in sentence:
if char.isalpha() or char.isdigit():
char = char.lower()
if char in frequency:
frequency[char] += 1
else:
frequency[char] = 1
print("Frequency of letters and digits:", frequency)

Screenshot of the output:

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.

d1 = eval(input("Enter first dictionary: "))


d2 = eval(input("Enter second dictionary: "))
print("First dictionary: ", d1)
print("Second dictionary: ", d2)
if len(d1) > len(d2):
longDict = d1
shortDict = d2
else:
longDict = d2
shortDict = d1
print("overlapping keys in the two dictionaries are:", end=' ')
for i in shortDict:
if i in longDict:
print(i, end=' ')

Screenshot of the output:

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)

Screenshot of the output:

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

a. print("Friends and their phone numbers:")


for name, number in phonebook.items():
print(name + ": " + number)

b. new_name = input("\nEnter name of new friend: ")


new_number = input("Enter phone number of new friend: ")
phonebook[new_name] = new_number
print(phonebook)

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)

d. mod_name = input("\nEnter name of friend to modify number: ")


if mod_name in phonebook:
mod_number = input("Enter new phone number: ")
phonebook[mod_name] = mod_number
print(mod_name + "'s phone number has been modified.")
else:
print(mod_name + " not found.")
print(phonebook)

e. check_name = input("\nEnter name of friend to check: ")


if check_name in phonebook:
print(check_name + " is present in the dictionary.")
else:
print(check_name + " is not present in the dictionary.")
f. sorted_keys = sorted(phonebook)
print("\nDictionary in sorted order of names:")
print("{", end = " ")
for key in sorted_keys:

41
print(key, ":", phonebook[key], end = " ")
print("}")

Screenshot of the output:

42

You might also like