2. Hindustan Chemicals Ltd.
is a company that deals in manufacture and export of chemicals across the worla
and has hundreds of employees on its roll., WIshes to computerize the process of salary generation. Write
aPython program to enter the names of emplovees and theirsalaries as input and store them in a dictionary
and also represent the data as a Salary Generation Report.
Ans.
#Program to create a dictionary which stores names of the employees
#and their salary and prints it in the proper format
num = int1 (input ("Enter the number of employees whose data is to be stored: "))
cont
lemployee dict () #Create an empty dictionary
while count num:
name = input ("Enter the name of the Eraployee: ")
salary =int (input ("Enter the salary: "))
employee [name] salary
count+1
print ("\n\nEMPLOYEE NAME\tSALARY")
for k in employee:
print (k, '\t\t', employee [k])
Enter the number of einployees whose data is to be stored: 2
Enter the name of the Employee: Rinku
Enter the salary: 30000
Enter the name of the Employee: Anu
Enter the salary: 50000
EMPIOYEE NAME SATARY
Rinku 30000
Anu 50000
UNSOLVED QUESTIONS Ch -1
1. What are the advantages of Python programming language?
2. In how many different ways can you work in Python?
3.What are the advantages/disadvantages of working in interactive mode in Python?
4. Write Python statement for the folowing in interactive mode:
(0) Todisplay sum of 3, 8.0, 6*12
(ii) To print sum of 16, 5.0, 44.0
5. Write a Python program that accepts a string and counts the number of upper and lower case letters in a
dictionary.
Sample String: Cricket World Cup 2023 in India I
Expected Output: {"LOWER","UPPER" 18}
6. Write a Python program that takes a list and returns a new list with distinct elements from the first list.
Sample List: [1,2,3,3,3,3, 4,2,5]
Unique List: [1, 2, 3, 4, 5]
-Review of Python Basics 1.69
7. Write the Python statement for each of the following tasks using built-in functions/
(i) To sort anumeric List object L1 in descending order. /methods only:
(ü) To delete marks of Sumit from a dictionary Marks where names are keys and
marks are
8. Predict the output of the Python code given below: values.
S= 'Computer@Science'
n = len (s)
m= T
for i in range (0, n):
if (s[i] >= 'a' and s i] <= 'm):
m= m+ s[i].upper ()
elif (s [i] >= 'n' and s(i] <= 'z'):
m=m + s[i-1]
elif (s [i].isupper ()):
m=m + s[i).lower ()
else:
m = m + '$$i
print (m)
9. Write the output of the
folowing:
(i) for i in
123':
print ("CPU", i)
(ii) for i in
[100,200, 300]:
print (i)
(ii) for j in range
(10,6,-2) :
print (j*2)
(iv) for x in range
(1,6) :
for y in range (1,
x+1) :
print (x,! ' y)
(v) for x in range
(10,20) :
if (x == 15):
break
print (x)
(vi) for x in range
(10,20) :
if (x % 2 == 0):
Continue
print (x)
10. Write the output of the
following program on execution if x = 50:
if x>10:
if x>25:
print (""ok")
if x>60:
print ("good" )
elif x>40:
print ("average")
else:
print ("no output")
1.70
-Computer Science with Pythar
11. What are the various ways of creating alist?
12, What are the similarities between strings and lists?
13. Why are lists called a mutable data type?
14. What is the difference between insert() and append() methods of a list?
15. Write a program to calculate the mean of a given list of numbers.
16. Write a program to calculate the minimum element of a given list of numbers.
17. Write acode to calculate and display total marks and percentage of astudent from agiven list storing the
marks of a student.
18. Write a program to multiply an element by 2 if it is an odd index for a given list containing both numbers and
strings.
19. Write a program to count the frequency of an element in a list.
20. Write aprogram to shift elements of a list so that the first element moves to the second index and second
index moves to the third index, and so on, and the last element shifts to the first position.
Suppose the list is [10, 20, 30, 40]
After shifting, it should look like: [40, 10, 20,30)
21. Alist Num contains the elements: 3, 25, 13, 6, 35,8, 14, 45
Write a program toswap the content with the next value divisible by 5 so that the resultant list will look like:
25,3, 13, 35, 6, 8, 45, 14
22. Write a program to accept values from a user in a tuple. Add a tuple to it and display its elements one by one.
Also display its maximum and minimum value.
23. Write a program to input any values for two tuples. Print it, interchange it and then compare them.
24. Write a Python program to input 'n' classes and names of class teachers to store them in a dictionary and
display the same. Also accept a particular class from the user and display the name of the class teacher of
that class.
25. Writea program to store student names and their percentage in a dictionary and delete a particular student
name from the dictionary. Also display the dictionary after deletion.
26. Write aPython program to input names of 'n' customers and their details like items bought, cost and phone
number,etc., store them in a dictionary and display all the details in a tabular form.
27. Write a Python program to capitalize first and last letters of each word of a given string.
28, Write a Python program to remove duplicate characters of agiven string.
29. Write a Python program to compute sum of digits of a given number.
30. Write a Python program to find the second most repeated word in a given string.
31. Write aPython program to change agiven string to anew string where the first and last characters have been
exchanged.
32. Write a Python program to multiply all the items in a list.
33. Write aPython program to get the smallest number from a list.
34. Write a Python program to append a list to the second list.
35. Write a Python program to generate and print a list of first and last 5elements where the values are square
of numbers between 1 and 30 (both included).
36. Wríte a Python program to get unique values from a list.
37. Write a Python program to convert a string to a list.
1.71
-Review of Python Basics
dictionaries to create a neW one:
38. Write a Python script to concatenate the following
dl = A':1, 'B':2, 'C':3}
d2 = 'D':4)
Output should be:
('A':1, 'B':2, 'C':3, 'D' :4)
39. Write a Python script to check if a given kev already exists in a dictionary.
40. Writea Python script to print a dictionary where the keys are numbers between 1and 15 (both included) and
the values are square of keys.
Sample Dictionary:
(1:1, 2:4, 3:9,4: 16,5: 25, 6: 36, 7: 49, 8: 64, 9: 81, 10: 100,11: 121, 12: 144,13: 169, 14: 196, 15: 225)
41. Write a Python script to merge two Python dictionaries.
42. Write a Python program to sort a dictionary by key.
43. Write a Python program to combine two dictionaries adding values for common keys.
dl = {!a': 100, 'b': 200, 'c':300}
d2 = {'a': 300, 'b': 200, 'd':400}
Sample output: Counter ({'a': 400, 'b': 400, 'c': 300, 'd': 400})
44. Write aPython program to find the three highest values in a dictionary.
45. Write a Python program to sort a list alphabetically in a dictionary.
46. Write a Python program to count number of items in a dictionary value that is a list.
47. Consider the following unsorted list: 105,99, 10, 43, 62, 8. Write the passes of bubble sort for sorting the
list
in ascending order till the 3rd iteration.
48. What will be the status of the following list after the First, Second and Third pass of the insertion sort
method
used for arranging the following elements in descending order?
28, 44, 97, 34, 50, 87
Note: Show the status of all the elements after each pass very clearly underlining the changes.
49. Evaluate the following expressions: (CBSE Sample Paper 2020-21)
(i) 6*3+4**2//5-8
(iü) 10>5 and 7>12 or not 18>3
50. What are comments in Python? Howisacomment different from indentation?
-Computer Sclence
1.72
Eunction that accepts a string
user-deflned lowercase 1etLers.
Ans. Wrlte a uppercase letters
and
Calculates the number of
Fand
def string test. (s) : "LOWERCASE'" : 0)
d=|"UPPERCASE": 0,
for c in s:
if c.isupper ) :
d["UPPERCASE"} +=l
elif c.islower () :
d[ "LOWERCASE"] +-1
else:
pass
:", )
print ("Original string c h a r a c t e r s : " , d["UPPERCASE"])
uppercase
print ("No. of characters: ",
d["LOWERCASE"])
of lowercase
print ("No.
Grow")
string test ("Play Learn and
Output:
Original string : Play Learn
and GroW
characters: 3
NO. O£ Upper case
characters: 13
No. of Lower case
Ch - 2
UNSOLVED QUESTIONS
designed than a program without any functions.
1. A program having multiple functions is considered better
Why?
returns the area of a
2. Write a function, calculate _area(), that takes base and height as input arguments and
triangle as an output. The formula used is:
Triangle Area = *base*height
2.60 -Gomputer Science with Python-XIl=
3. Modify the function given in the previous guestion to take a third parameter called shape ype.
Shape type should be either triangle or rectangle. Baspd on the shape. it should calculate the area.
Formula used: Rectangle Area = length*width
4. Write a function, print_pattern(), that takes integer number as argument and prints the following pattern ir
the input number is 3.
***
If input is 4, then it should print:
***
5. Write the utility of the following:
(i) Default Arguments
(i) Keyword Arguments
6. Describe the different types of functions in Python using appropriate
examples.
7. What is scope? What is the scope-resolving rule of Python?
8. What is the difference between local and global variables?
9. Write the term suitable for the following descriptions:
(i) A name inside the parentheses of a function header that can receive a value.
(iü) An argument passed to a specific parameter using the parameter name.
(ii) Avalue passed to a function parameter.
(iv) Avalue assigned to a parameter name in the function call.
(v) A
name defined outside all function definitions.
(vi) A
variable created inside a function body.
10. What will the following function return?
def addEm (x, y, z) :
print (x + y + z)
X=y=z=10
11. What willbe the output when addEM(0 is called/executed?
def addEM (x, y, z):
return x + y + z
X=y=z=20
12. What will be the output of the following programs?
0) num = 1
def myfunc () :
return num
print (num)
print (myfunc ()
print (num)
() nun = 1
def myfunc () :
num = 10
return num
print (num)
print (myfunc (0)
print (num)
-Functions 2.61
(iii) num 1
def myfunc ():
global num
num = 10
print (num)
print (my func ())
print (num)
(iv) de f display () :
print ("Hello",)
display ()
print ("bye!")
13. What is wrong with the following function definition?
def addEm (x, y, z) :
return x + y + z
print ("the answer is :", x + y + z)
14. Predict the output of the following code:
a = 10
y =5
def myfunc (a) :
y= a
a = 2
print ("y=", Y, "a=", a)
print ("aty", a + y)
return a y
print ("y=", y, "a=", a)
print (myfunc (a))
print ("y=", y, "a=" a)
15. Find the errors in the code given below:
define check ()
N =input ('Enter N:!
I =3
Answer = 1 + i ** 4/N
Return answer
16. Define flow of execution. How does it work with functions?
17. Write afunction that takes amount in dollars and dollar-to-rupee conversion price and then returns the
amount converted to rupees. Create the function in both void and non-void forms.
18, Write a function to calculate the volume of a box with appropriate default values for its parameters.
Your function should have the following input parameters:
() Length of box
(ü) Width of box
(iii) Height of box
Test it by writing a complete program to invoke it.
19. Write a program to find the greatest common divisor between two numbers.
2.62 -Computer Sclence with Python-X
20. Write a Python function to multiply allthe numbers in a list.
Sample List: (8, 2, 3, -1, 7)
Expected Output: -336
21. Write a Python function to calculate the factorialof a number (a non-negative integer). The function accepts
the number whose factorial is to be calculated as the argument.
22. Write aPython function that takes a number as a parameter and checks whether the number is prime or not.
23. Write a Python function that checks whether a passed string is a palindrome or not.
Note: Apalindrome is a word, phrase or sequence that reads the same backward as forward, e.g., madam,
nurses run, etc.
24. Write a Python program that accepts a hyphen-separated sequence of words as input and prints the words
in a hyphen-separated sequence after sorting them alphabetically.
Sample Items: green-red-yellow-black-white
Expected Result: black-green-red-white-yellow
25. Predict the output of the following codes.
(a) def code (n):
if n == 0:
print ('Finally')
else:
print (n)
code (3)
code (15)
(b) def code (n):
if n=0:
print ("Finally')
else:
print (n)
code (2-2)
code (15)
(c) def code (n):
if n =0:
print ('Finally')
else:
print (n)
code (10)
(d) def code (n):
if n==0:
print ('Finally')
else:
print (n)
print (n-3)
code (10)
-Functions 2.63
26. Predict the outputof the followingcode:
def express (x, n):
if n == 0:
return 1
elif n 2 == 0:
return express (x*x, n/2)
else:
return x* express (x, n-1)
express (2,5)
27. Write a method in Python to find and display prime numbers from 2 to N. The value of Nshould&
passed as an argument to the method.
28. Write a method, EvenSum(NUMBERS), to add even values given in the tuple named NUMBERS.
29. Write a program using user-defined function to calculate and display the average of all the elements in
user-defined tuple containing numbers.
30. Name the built-in mathematical function/method:
(0) Used to return an absolute value of a number.
(i) Used to return the value of x', where x andy are numeric expressions.
(ii) Used to return a positive value of the expression in float.
31. Name the built-in string function:
() Used to remove the space(s) from the left of the string.
(ii) Used to check if the string is uppercase or not.
(ii) Used to check if the string contains only whitespace charactersor not.
32. Write a function, LeftShift(lst,x), in Python which accepts numbers in a list (Ist) and all the elements of the
list should be shifted to the left according to the value of x.
Sample lnput Data of the list
lst= 20,40, 60,30,10,50, 90, 80,45,29] where x=3
Output lst = (30,10,50, 90,80,45,29,20, 40,60].
2.64
the digital devices.
() Which block in Chennai division should host the
server? Justify your answer.
(iü) Which fast and effective wired transmission medium should be used to
connect the prime office at
Bengaluruwith the Chennai division?
(iv) Which network device willbe used to connect the digital devices within each location of
Chennai division
so that they may be communicate with each other?
(v) Aconsiderable amount of data loss is noticed between different locations of the Chennai division, which
are connected in the network. Suggest a networking device that should be installed to refresh the data
and reduce the data loss during transmission to and from different locations of Chennai division.
UNSOLVED QUESTIONS
1. What is Internet?
Ch - 6
2. What is a Network?
3. What are the various types of topologies?
4. What is the range of frequency for radio waves?
3. 18 Gbps is equal to how many bits per second?
6. Write short notes on the following:
(a) Bandwidth (b) Bluetooth
(c) Data Transfer Rate (d) HTTP
1. Two universities in different states want to transfer information.Which type of network do they need to use
for this?
8. Draw a network layout of star topology and bus topology connecting five computers.
-Computer NetworksS 6.53
9. Rohit, aClass XI student, has just started understanding the basics of the internet and weh technolovioe
the tor
He is a bit confused about the terms 'World Wide Web' and 'Internet', Help hirm understand both
with the help of suitable examples of each.
10. Describe Bus Topology and Star Topology.
11, Define the following terms:
(a) Baud (b) Communication Channel
(c) Hub (d) Repeater
12. What is modem? Define the functioningof internal and external modems.
13. Expand and explain the following terms:
(a) PPP (b) POP3
(c) VolP
14. Describe the following networking devices:
(a) Routers (b) Gateways
15. What are Wi-Fi Cards? Explain.
16. What is a Communication Protocol? What is its role in networkíng?
17. What is HTTPs? How does ít work?
18. What is Ethernet? What is Ethernet Card?
19. What are Hubs? How are actíve hubs different from passive hubs?
20. What are the facilities provided by a server in anetwork environment?
21. Which communication medium is to be suggested for very effective and fast communication in a guided
medium?
22. In a harsh industrial environment, which cable would you like to use?
23. Which transmission medium has the ability to communicate over oceans?.
24. What is the difference between Microwave and Radio Wave Transmission?
25. Which transmission medium is useful in sparsely populated areas?
26. Which network topology is easy to expand?
27. Which device filters data and which device can handle different protocols?
28. What are the goals and applications of a computer network?
29. Write some advantages and disadvantages of the following:
(a) Optical fibres (b) Coaxial cables
(c) Twisted pair cables (d) Radio waves
(e) Microwaves (f) Satellites
30. Explain the role of HTTP Protocol.
31. Differentiate between Hub and Switch.
32. Differentiate between Circuit and Packet Switching.
33. What is the role of a Switch in a network?
34. Differentiate between MAC and IP Address.
35. Explain briefly:
(a) HTTP (b) TCP/P
(c) FTP
36. When would youprefer the following?
(a) hubs over repeaters
(b) switches over other networking devices
37, Differentiate between web server and web browser. Write any two popular web browsers.
(CBSE Sample Paper 2020-21)
38. Name the protocol that is used to send emalls. (CBSE Sample Paper 2020-21)
6.54 -Computer Science with Python-XI|
Assertion (A): Exception handling code is clear and
3.Reasoning (R): The code where unexpected block based in Python.
run-time
the action takes place when an exception occurs. exception may occur is separate from the code where
4, Assertion (A): No matter what exception occurs; you can always make sure that : Some Common action takes
place for all types of exceptions.
Reasoning(R): The finally block contains the code that must execute.
Ans. 1. (i) 2. (i) 3. (i) 4.(i)
UNSOLVEDQUESTIONS Ch - 3
1. What. all can be the possible outputs of the following code?
def myfunc (x=None):
result = nn
if x is None:
result = "No argument given"
elif x == 0:
result = "Zero"
elif 0 <x =3:
result = "x is between 0 and 3"
else:
result = "x is more than 3"
return result
C= myfunc (3.5)
print (c)
2. List the situation(s) in which the following errors occur:
(a) IOError
(b) NameError
(c) ValueError
(d) TypeError
3. Name three run-time errorsthat occur during Python program execution.
4. What is the difference between an error and an exception?
code to illustrate it.
3. How can you handle an exception in Python? Write sample
b. Name some common built-in exceptions in Python.
I. What does the finally clause produce in a try...except block?
8. Write syntax of raise statement.
9. Differentiate between IOError and IndexError.
is printed if the number conversion is not
40, Show how to modify the following code so that an error
successful:
val = input ("Enter a number")
pval = int (val)
3.23
-Exception Handling
11. Consider the code given belowand fillin the blanks with appropriate error types:
loop=1
while loop == 1:
try:
a = int (input('Enter the first number: ')
b= int (input('Enter the second number:)
quotient = a/b
except
print ("Error: Please enter only numbers")
except
print ("\n Error: Second number should not be zero")
except
print ("\n Unsupported operation: Check the
else: date type")
print ("Great")
finally:
print ("Program
loop = int (input (' Press 1 execution completed")
to try again !')
continue