GOVIND VIDYALAYA
TAMULIA
======================
Question Bank
Session 2014-15
Subject-Computer Science with PYTHON
Subject Code-083
STD XI
General Instruction:
=====================================================================================
MODULE-A
The following chapters are in portion of Mid Term Examination.
UNIT 1:COMPUTER FUNDAMENTALS
MODULE-B
The following chapters are in portion of Final Term Examination.
UNIT 3:INTRODUCTION TO PYTHON
Chapter 1:-Introduction/Overview of Python
Chapter 2:-Input/output in Python
Chapter 3:-Operator and Expression In Python
Chapter 4:-Working with Math Module
Chapter 5:-Branching and Looping in Python
Chapter 6:-User-Defined Function in Python
UNIT 4:PROGRAMMING WITH PYTHON
Chapter 1:-Working with Strings and Lists
Chapter 2:-Working with Directories and Tuples
Copyright: Govind Vidyalaya Tamulia
Acknowledgement
The will of God will never take you where Grace of God will not protect you."
Thank you God for showing me the path. . .
I owe deep gratitude to the ones who have contributed greatly in completion of this wonderful
Edition of this Question Bank for Academic Session 2014-15. Foremost, I would like to
express my sincere gratitude to my Managing Director Sir, Honorable Principal and
Administrator of This Institution for providing me such a platform and given all possibilities to
work on challenging areas of technology. I express my heartiest gratitude to all my elders
guidance, support, and encouragement during the task assign to me.
It has been a great honor and pleasure for me to do this kind of fruitful task for the better
output and best academic power towards the students of GOVIND VIDYALAYA TAMULIA.
I thank all the members of the Department of Computer Science & Information Technology,
and the Institute, who helped me by providing the necessary resources & support, for the
completion of my work. Finally, I thank my parents and almighty for their unlimited support
and strength. Without their dedication and dependability, I was not able to complete my work
on time.
Thanking You:
Vikash Anand
HOD-IT/CS & Developer: (Question Bank)
GOVIND VIDYALAYA TAMULIA
Unit Name
COMPUTER FUNDAMENTALS
PROGRAMMING METHODOLOGY
INTRODUCTION TO PYTHON
PROGRAMMING WITH PYTHON
TOTAL
MARKS
10
12
18
30
70
Time: 3 Hours
S. No.
01
Max. Marks: 70
Very Short
Short
Short
Long
Answer
Answer-I
Answer
-II
Answer
Typology of Questions
(SA-I)
(SA-II)
(VSA)
(L.A.)
(2 marks) (3 marks)
(1 mark)
(4 marks)
Knowledge Based
3
3
02
Conceptual
Understandigs
03
13% '
11
15%
Application Based
and Inferential type
16
23%
04
Reasoning Based
1.
16
23%
05
Skill Based
18
26%
11
70
100%
Total
Total
%
Marks Weightage
Notes:
1. No chapter wise weightage. Care to be taken to cover all the chapters.
2. The above template is only a sample. Suitable internal variations may be made for generating A similar template
keeping the overall weightage to different form of questions and typology of Questions same.
3. For Better References (Nos.1) Sample Question Paper are Design Based on Boards Curriculum In the end of
this Question Bank.
4. Abbreviations:
VSAQ-Very short answer question
SAQ I -Short answer question
SAQ II- Short answer question(Type-II)
LTQ-Long type question.
MODULE-A
Unit-1-COMPUTER FUNDAMENTALS
Chapter 1:-Evolution Of Computer:
Short Type Questions [1/2 Marks] [VSAQ/SAQ-I]
1. What is the function of mouse?
2. Which of the following are parts of the CPU?
(i) ALU
(ii) Memory
(iii) Control unit (iv) Input device
(v) Printer
3. Results are obtained from computer through its... unit. (Input/Output/CPU)
4. What are four basic components of a computer system?
5. What is a computer?
6. Who is the father of computer?
7. In which year was the Pascal's adding machine invented?
8. Which component is called as the brain of a computer?
9. What are the main characteristics of a computer?
10. Which part of the computer is responsible for processing?
11. In which era was the Abacus developed?
12. List the measurement units of computer speed.
13. Give at least two examples each of input and output units.
14. Give two major innovations in the first-generation computers.
15. Give two major innovations in the third-generation computers.
16. What is booting?
17. Name the types of computers that NASA and ISRO use to track and control space discovery.
18. Why do people prefer to use micro computers for their personal use?
19. Where do you see the use of analog computers?
Chapter 2:-Computer Software:
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
31.
32.
5
35.
36.
37.
38.
39.
40.
41.
42.
43.
44.
45.
46.
47.
None of these
Define First-Come-First-Serve (FCFS) scheduling.
Define compaction.
What is contiguous memory allocation?
What is the degree of multiprogramming?
What is directory?
In the file system, what does a directory contain?
What is the basic function of a mobile OS?
Define a process.
How does a computer program relate to a process?
Define scheduling and scheduler.
What is a Process Control Block (PCB)?
Name the information that a Process Control Block stores.
Name the three types of schedulers.
Convert (25)10(?)
Convert (3ABC) 16 (?)8
Convert (256)8 (?) I0
Convert (110011)2 (?)I0
Convert (2AB) 16 (?)2
Convert (273)8 (?)2
Convert (26)10 (?)16
Convert (38.20,0 (?)2
Convert (372)8 (?),0
Convert (100111010)2 (?)8
Convert (1010111010)2 (?)16
Convert (11001111)2 (?)16
Convert (11001111)2 (?)8
Convert (25)8 (?)Io
Convert (10001)2(?)Io
In which form does each computer store numbers, letters and other characters?
Which of the following is a measurement unit of computer system?
In binary subtraction, 0 1 = 1 and borrow 1 from the next more significant bit. Is it true?
In binary multiplication, 1 x 1 = 1 and no carry or borrow bits. Is it true?
Which categories of data are used in digital computers?
Explain EBCDIC.
Which digits are used in hexadecimal number system?
Which number system is used by computers?
What is the base of octal number system?
What is the base of hexadecimal number system?
Convert (45)10 to binary using division method.
Convert (101101)2 to its decimal equivalent.
Convert (288)10 to its octal equivalent.
6
76. Convert (440)8 to its decimal equivalent.
77. Convert (288)10 to its hexadecimal
78. Convert (120)16 to its decimal equivalent,
79. Convert (120)16 to its decimal equivalent,
80. Convert (120)10 to its Binary equivalent,
Chapter 5:-Microprocessor
81.
82.
83.
84.
85.
86.
87.
What is a microprocessor?
Name the basic components of a microprocessor.
What is a register?
What is the bit size of recent Intel Pentium computers?
What is clock speed? How is it measured in a computer?
What is a system bus?
What is a control bus?
88.
89.
90.
91.
92.
93.
7
114. What is the use of a power connector?
115. What types of connectors are used in a modem?
116. What is Bluetooth?
117. How is the LPT port designed
118. What is the use of SMPS?
119. Who developed the PS/2 port?
120. Which port is connected to the mouse wire?
121. What is the use of infrared port?
122. Write the steps to connect a cable with infrared port.
123. Name the device which is connected to serial port.
124. Name the devices which can be connected to USB port.
125. Why do we need an UPS with the computer system?
-------------------------------------------------------------------------------- UNIT 2:PROGRAMMING METHODLOGY
Chapter 1:-Programming Methodology and techniques
126. What is a modular programming?
127. What is robustness?
128. Name three types of debugging errors. What types of error computer can detect?
129. Give the characteristics of a good program?
130. What is the portability of a program
131. What do you understand by testing and debugging of program?
132. What is representational error?
133. How can you choose a variable in programming?
134. What is a problem definition?
135. Write the methods that are used to analyze a problem step-by-step.
136. What are relational operators?
137. What is a dry run?
138. What will be the minimum number of inputs for finding a simple interest?
139. What is the use of arithmetic operators?
140. What is iteration construct?
141. What is a logical operator? Give an example.
Chapter 2:- Algorithm and Flowcharts
142. Define algorithm?
143. Define flowchart?
144. What are the minimum requirements to draw a flowchart?
145. What is the purpose of a decision box in a flowchart?
8
7. State five benefits of using a computer.
8. Define the terms input and output.
9. What are the functions of a computer ?
10. Explain the Pascal's Arithmetic Engine.
11. Describe the first-generation computers.
12. Describe the fourth-generation computers.
13. Give some characteristics of the first-generation computers.
14. Describe the functional units of the computer.
15. What are the functions of the control unit?
16. Distinguish between volatile memory and nonvolatile memory.
17. What are the limitations of a computer system?
18. Differentiate between cold booting and warm booting.
19. Classify the computers according to the sizes they offered.
20. What are the primary functions of the CPU ?
21. Differentiate between digital computers and analog computers.
22. Fill in the blanks.
a) A printer that forms characters out of a set of dots is called
b) There are two basic types of disks ..and
23. Give the full form of following :
(i) CPU
(ii) LSI
24. What is the use of memory? What are its measuring units?
9
47.
48.
49.
50.
51.
52.
53.
54.
10
80. Convert (0.752)10 to its binary equivalent.
Chapter 5:-Microprocessor
81. What is the function of arithmetic logic unit?
82. Define the following :
(i) Data bus
(ii) Address bus
83. Define the following :
(i) Program counters (ii) Accumulator
84. What are the two units for measuring CPU clock speed ?
85. What happens when a computer is turned on?
86. What are the functions of control unit?
87. In Microprocessor design, name any three registers and their purposes.
88. Why are registers essential for a computer CPU?
89. Why do you need a CISC processor? What is its goal?
90. Write down the major characteristics of RISC processor.
91. Write down the major characteristics of CISC processor.
92. Explain the role of different registers for data processing.
93. Distinguish between instruction set and instruction cycle.
94. Differentiate between register and bus.
95. Differentiate between CISC and RISC processors.
96. State two differences between address bus and data bus.
97. Differentiate between program counter and instruction register.
98. Briefly, explain the working of control unit in a microprocessor.
11
12
(i) Num= 2*3-4 (ii) Num = 2+3-1*3 (iii) Num = (2+3)*2 (iv) Num = 3* *4+5
133. What value will be stored in different variables when the following Python statements are
executed?
i =10
j = i+5
k= i+j/5
1=k+1
m=1+ 1i
n=k+m*1
Print
Print ("i = %d, j = %d, k = %.2f, I = %.2f, m = %.2f' % (i, j, k, 1, m)
134. Correct the error(s), if any, in the following statement :
(i) 3* 5 = x
(ii) l*b = area
(iii)1= ab + c*d
(iv) A = P * R * N/100
135. Write the statements for the each situation as given below :
(i) Assign a value 2 to variable A.
(ii)Assign the value of variable N to variable N1.
(iii) Print the string "February" on the screen.
(iv) Assign the value represented by the formula A2+B2+C to variable X.
136. Write the Python expressions for the each situation as described below :
(i) Increase the value of variable count by 2.
(ii)Assign the value 3 to variable Cl, C2, C3.
(iii) Assign 20, 30, 40, and 40 to variables V1, V2, V3 and V4 respectively.
(iv) Print the statement "Hello! World" in the following format: Hello! World.
137. Write the Python expressions for the each situation as described below :
(i) Assign a Boolean value False to Flag.
(ii)Double the value assigned to variable C.
138. In each of the following cases, show how comment can be placed in the Python program.
(i) Add the program heading Sum of the odd and even numbers.
(ii)Add the comment average value to the statement : x = sum/n
139 Evaluate the following Python expressions when values of a, b, d = 5, 3, 1.5
(1) C = a - (++b) *(--d)
(ii) f = (++b)*b - a
(iii) C=d*a+b
( i v) f =a+b/ a
(v) C = (++a) * d + a
140. Write an example of each part?
I.
Literals
II.
Fundamental data types
III.
Python file extension
13
8. What is the role of flowchart in high-level programming?
9. Mention the characteristics of an algorithm.
10. Draw a flowchart to find the sum of two numbers.
11. Draw a flowchart to accept a number and print the cube of that number.
12. Write an algorithm to find the greatest of the three given numbers.
13. Write an algorithm and flowchart to compute the sum, average and product of any of three numbers of your
choice.
14. Write an algorithm that prints the greatest number of two given unique numbers.
15. Write an algorithm that can read 20 integer values and print the total.
16. Draw a flowchart to find whether a number is even or odd.
17. Draw a flowchart to read two numbers and display the numbers in the decreasing order.
18. Draw a flowchart to find the greatest number of the given two unique numbers.
19. Draw a flowchart to find the greatest number of any three numbers A, B, and C.
20. Write an algorithm to find whether a given number is odd or even.
21. Draw a flowchart to find the sum of first 10 natural numbers.
22. Write an algorithm which will calculate the sum of first 'N' multiples of an integer 'Ni' i.e. . 1 x N1
+ 2 x N1 + +N x NL.
23. Write an algorithm to print total number of negative (-) and positive (+) numbers and zeroes (0).
24. Write an algorithm to read a set of 20 numbers and make a sum of all non-negative numbers in this set of
numbers.
25. Draw a flowchart for computing factorial 'N' (N!)
Where N! = 1 x2 x 3 x x N.
26. Write an algorithm to calculate the sum of 'N' odd and even numbers.
27. Write an algorithm to compute the sum of the squares of 'N' numbers.
28. Draw a flowchart to compute the sum of the squares of 'N' numbers.
29. Write an algorithm to input 'N' numbers and find the greatest number among them.
30. Draw a flowchart to find the sum of the series :1' + 2' + 3' + + N' - - - - (N (N + 1)]
31. Develop an algorithm (step-by-step solution) for a selected integer between 0 and 100. Let this number
be the marks scored by a student in a particular test. Convert this integer (number) into letter grades (A, B,
C, D, E) as given in the table below:
Numerical Condition
Letter Grade
,
< 40
>=40 and <= 54
>= 55 and <= 69
>= 70 and <= 85
> 85
E
D
C
B
A
--------------------------------------X------------------------------------
14
MODULE-B
The following chapters are in portion of Final Term Examination.
UNIT 3:INTRODUCTION TO PYTHON
Chapter 1:-Overview of Python
Chapter 2:-Input/output in Python
Chapter 3:-Operator and Expression In Python
Chapter 4:-Working with Math Module
Chapter 5:-Branching and Looping in Python
Chapter 6:-User-Defined Function in Python
UNIT 4:PROGRAMMING WITH PYTHON
Chapter 1:-Working with Strings and Lists
Chapter 2:-Working with Directories and Tuples
Unit-3-INTRODUCTION TO PYTHON
Chapter 1:-Overview of Python:
Short Type Questions [1/2 Marks] [VSAQ/SAQ-I]
1. How can we declare variables in Python?
2. What is dynamic type? Give example.
3. What is IDLE?
4. What is script? Where can you write the Python Code?
5. Why a banner saying "RESTART" is always displayed in Python program execution?
6. What is a keyword?
7. Name the key attributes of a Python object,
8. How can you define the string literals in Python?
9. Explain the following command: Print ("Hello World.")
17. When we write a statement like a, b, c,d=1, 2, 3, 4 What does you call it?
18. Name five standard data types in Python.
18. Differentiate between single quotes, double quotes and triple quotes
19. How can you create a complex literal in Python?
21. Name two sequence types and set types in Python.
22. How can you create an empty list in Python?
23. Is string a sequence type data type?
24. How can you create an empty tuple in Python?
25. What is the use of Del statement?
26. What is Python?
27. Who created Python?
28. Why is Python an interpreted language?
29. Why is Python an interactive language?
30. What is Python shell?
31. Why is Python an object-oriented language?
32. What does a variable hold in Python?
33. How can we declare variables in Python?
34. What is IDLE?
35. What is script? Where can you write the Python code?
36. Why a banner saying "RESTART" is always displayed in Python program execution?
37. Name five major platforms where Python is available.
38. Why is it necessary to set Python in system's environment variable?
39. What do you get after starting the Python in IDLE mode (Python GUI)?
Copyright: Govind Vidyalaya Tamulia
15
40. What will be the Python statement to print a message like "Welcome to Python?
41. What are keywords?
42. What are the console I/O functions?
43. What do you mean by an identifier?
44. What is a variable?
45. What is scalar variable?
46. A literal is a sequence of characters surrounded by double quotes.
47. Name the Python operator which is responsible to declare variables.
48. How are comments written in a program?
49. What is indentation of a program?
50. What do you understand by the character set of a language?
51. What are the various components of Python character set?
52. What do you mean by a token?
53. Name any four tokens of Python.
54. List the three types of numbers supported by Python.
55. What are floating-point numbers?
56. What are character/string constants?
57. What are floating point constants?
58. In a statement like "print (" {0} {1} {2} "format (vall [0], val2 [1], val2 [2]))", what is 0, I and 2?
59. What are escape sequences?
60. Which escape sequences represent the newline character and tab?
61. What is the extension of a Python script program?
62. What is an operator?
63. What is an operand?
64. What is an arithmetic operator?
65. List different arithmetic operators.
66. How '/' operator is different from "/o' operator?
67. What is a unary operator?
68. What is a binary operator?
69. What are relational operators?
70. List different relational operators.
71. If p = 9.8, what will be the result of int (p/9)?
72. What are logical operators?
73. List different logical operators.
74. What is a statement?
75. Which operators are used to combine relational expressions?
76. Which types of operators are used to compare the values of operands?
77. What happens if one of the operands of a logical and operator is false?
78. What happens if one of the operands of a logical or operator is false?
79. What is an assignment operator?
80. What is compound assignment?
81. What is modulus operator (%)?
82. The modulus operator works only with integers true or false.
83. The operator is same as the assignment operator (=) True or False.
84. What is the difference between `=' and operators?
85. What is the purpose of comma operator (,)?
86. What is an expression?
87. Name the two functions which are helpful to convert string input into number format.
Copyright: Govind Vidyalaya Tamulia
16
88. Name some common syntax error messages displayed by Python.
89. Write a statement to print "Harish" five times.
90. What will be the output of the following statement print (3 - 10**2 + 99/11)
Chapter 2:-Input/output in Python
91. If you type the following code in interactive mode, what it wM print and W h y ? print ("Python",
"Programming.")
92. Where do you place the keyword parameters like end and Sep?
93. What does the default value print by Sep argument with print () function?
94. What does the default value print by end argument with print () function?
95. What is the use of % operator with print () function?
96. What is the purpose of the following statement?
TMark = int (irrupt ("Enter your total mark :"))
97. What does an input () function return?
98. What will happen if you do not use prompt with input () function?
99. What is the output of the following:
( a) print ("My percentage is: %.2F" 89.9625)
( b) print ("My percentage is: %d" % 89.9625)
100. What is print function?
101. What is the input function?
102. Differentiate between input () and rawinputO function?
Chapter 3:-Operator and Expression In Python
103. How do we convert a string to a number in Python?
104. What will the code produce? Print (type (112))
105. Can we do ++x and x++ in Python?
106. If you write the following statements? What will be the output of the following program
segments?
(a) A = 5
(b) a, b=1, 2, 4
(c)a,b=0,30;
A=25 + 4 -4
a+=4;
a=30/b*b;
Print (A)
print (int (a/2))
print (a);
107. What will be the output of the (a) x = 5
( b)a = 25 + 4 - 4
Print (++x)
print (a)
108. What will be the output of the following code?
(a) a = p.
(b) a=1;
a, b = a+1, a+1
b=1;
Print (a)
a, b = b, a
Print (b)
print ("%d % d" % (a , b))
109. What ail options will work? Write the comments for the following expressions.
(a) n= 1
(b) n = 1
(c) n = 1
Print (n++)
Print ++n
print (n += 1)
(d) n = 1
(e) n
Print (n = n+1)
n=n+1;
Print (n)
Chapter 4:-Working with Math Module
110. What are modules?
111. What is dot (.) notation in python?
112. How do you get a random number between 1 and 100 using random() function ?
113. Write the equivalent Python expression(s) for the following : x = Va2 + b2 + c2
Copyright: Govind Vidyalaya Tamulia
17
Assume that a = 2, b = 3, c = 2.
114. Write the Python expression(s) for the following : a = ex x Assume that x = 2.
115.Write the equivalent Python expression(s) for the following : b=(R+S) Assume that R = 2 and S = 4.
116. Write the equivalent Python expression(s) for the following :c = 2 4y * (P + Q)2 Assume that y = 2, P
= 4 and Q = 3
117. Write the equivalent Python expression(s) for the following: d = A + B + eY Assume that A = -4, B = 4
and y = 5.
118. Write the equivalent Python expression(s) for the following e = (A + + (C + D)4 Assume that A = 3,
B= 2, C = 5 and D = 5.
119. Write the equivalent Python expression(s) for the following :
root 1 = (b) + V| (b2 4ac)
/2a NOTE - Assume that a = 3, b = 4 and c = 2.
120. Write the equivalent Python expression(s) for the following :
z = x' + y3 v |xy/2
Assume that x = 3 and y = 4.
121. Why is the following statement not executed?
math.cos (math.pi / 4)
122. What will be the output of the following lines ?
(i) Import random
Random. Choice (['White line', 'Green line', 'Blue line'])
(ii) Import random
random.randrange (6)
123. Translate the following mathematical expression into an equivalent Python expression(s). Assume that
the math library has been imported.
x = /r (cos a) 2 + r (sin a)
Chapter 5:-Branching and Looping in Python
124. What is a sequence construct? IL What is a selection construct?
125. What is branching?
126. Give two examples of control structure.
127. What is iteration construct?
128. What is the body of the loop?
129. What is Boolean value?
130. What is an exit condition?
131. What is an alternative name of exit condition?
132. What is conditional statement?
133. What is a while loop ?
134. What is the name of the construct used in the following statement and how does it operate?
x = a if (a>b) else b
135. What the use of continue statement?
136. What is the purpose of a for loop?
137. What is pass statement?
Chapter 6:-User-Defined Function in Python
138. What is a user-defined function?
139. Name the keyword that indicates the function definition.
140. What are parameters?
141. What is fruitful function?
142. What is void function?
143. Define flow of execution.
144. What is a global variable?
145. What are the roles of the arguments in a function ?
146. How will you call a function that contains arguments?
Copyright: Govind Vidyalaya Tamulia
Developed by: Vikash Anand-HOD [IT/CS]
18
147.
148.
149.
150.
151.
152.
19
176. What will be the output of the following code ?Metro = {1:"Delhi", 2:"Mumbai", 3:"Chennai",}
177. Is tuple object support item assignment?
178. State two differences between tuple and list.
What is operator?
What is arithmetic operator?
What is the difference between / and % operator?
What is relational operator? Give two relational expressions.
20
28.
29.
30.
31.
32.
33.
34.
35.
36.
21
51.
52.
53.
54.
55.
56.
57.
58.
59.
60.
61.
If x has a value greater than 20 then increment the value of the k by I otherwise decrement the
value by 2.
Write an appropriate for or while loop for the following situations :
(1) A loop is to be repeated 200 times.
(ii) A loop is to be repeated 200 times, but the loop is to be terminated if the value of the variable X
becomes 175.
What output will the following code fragment produce ?
n = 1000
Val = int (input ("Enter a value: "))
Res = 400 if (n + Val > 1750) else 200
Print (res)
If the input is 2000
If the input is 1000
If the input is 500
Use of an if statement to compare the value of an integer called sum against the value 65 and if it is
less, print the text string "Sorry, try again".
Write a for loop to print the values from 1 to 10 in separate lines.
Write a for loop which calculates the sums of all values between 0 and 100 into a variable called
total.
Write a for loop to print the character from A-Z in a single line with one space like A, B, D, Z.
If variable total is equal to the variable good guess, print the value of total, otherwise print the value
of good guess using if statement.
What is abbreviated operator? What will be the output of z in the following expression:
z = 150 if (y x > 500) else 50
If the input is:
(i) x, y = 300, 700
(ii)x, y = 700, 800
Write Python statement for the following :
If variable sum is equal to 10 and total is less than 20, print the text string "Incorrect" using if statement.
22
66. What will be the output of the following code ?
j, i = 1, 2
while (i< 5):
j =i *
i= i + 1
23
72. Write a program that prints 1 2 4 8 16 32 64 128.
73. Find the error(s), if any in the following program: const MAX = 4
a = int(("Enter the value of a: "))
b = int(input("Enter the value of b: ")) if (a > b):
MAX=5
for in range(0, MAX):
print ("%d" %(x))
74. Find the error(s), if any in the following program:
sum = value = inct = 0
for i in range(0, 11)
value = int(("Enter value :")) sum = sum + value
inct = inct + 1
avg=sum\inct
print("The average is %d" %(avg))
75. Find the syntax error(s), if any, in the following program : W == 90
R
while (W > 60)
R = W 50
if (R = 20):
print("Lower Range") elif (R == 30):
print("Middle Range") elif (R == 40):
print("Higher Range") = W 1
76. Find the syntax error(s), if any, in the following program :
X = int(("Enter value of X :"))
for in range(0, 11):
if (X Y):
print("%" %(X+Y))
else:
print("%d" % Y)
77. Find the syntax error(s), if any, in the following program :
x = int(("Enter value of x :"))
for y in range(1, 6)
print("" %y)
print("%d %d" %(x,y))
78. Give the output of the following program segment :
a, b, c = 300, 0, 0 if (a >= 400):
b = 300
print("%d %d %d" %(a,b,c))
79. Rewrite the following set of if else statements in if. Else if statements.
num = int(input("Enter the number : "))
if (num = = 5):
val = num * 25 - 20
print("%d" %(num + val))
else:
if (num = =10):
val = num * 20 - 15
print("%d" %(val - num))
-
24
25
b=b+1
26
27
100.
j = j * 2 return j
i=4
a = add(i)
print("%d" %a)
Give the output of the following program : def fl (b):
x=b*b
return x
101.
102.
103.
104.
28
Print ("%d %d %d" %(a, a, b))
------------------------------------------------------------------------------------------------------------------------------------------ UNIT 4:PROGRAMMING WITH PYTHON
Chapter 1:-Working with Strings and Lists:
105. Differentiate between mutable data value and immutable data value.
106. What is a negative index in Python ?
107. Write Python statements for the following :
(1) Assign x as convert string of digits "12345.70" to float type.
(ii) Assign y as convert integer type to string : ival = 100
108. Consider the following statement and answer the (i) and (ii) parts. String = ("Hello", "Python",
"Programmer")
(1) What is "len(String)" ?
(ii) What is "list(String)" ?
109. Differentiate between upper() and isupper() functions.
110. What will be the output of following program code ?
str = "MyPython Programming"
ctr = len(str)
print (str[0:5])
print (str[l :5])
print (str[:-4])
print (str[0:161)
print (str[:20-4])
111. What will be the output of following program code ?
List = ["MyPython", "Programming", "in", "Python"]
ctr = len(List)
print (List[0:2])
print (List[1:2])
print (List[:-2])
print (List[:1])
print (List[:0])
112. What will be the output of the following program segments ?
(i) listl = [1,2,3,4]
list2 = [3,4,5,6]
list3 = listl + list2
print (list3) listl.extend(list2)
print (listl)
(ii) number = [20, 30, 40, 10, 50, 60, 90, 80, 70]
number = number. sort()
print (number)
(ii) list = ["Mon", 45, "Tue", 43, "Wed", 42]
print (list[ 1 :-1]) list[0:2] = 'Z'
print (list)
113. If a list M contains the following values :
[5, 112, 203, 124]
[10, 114, 27, 18]
[11, 1 1 0 , 2 1 , a n d 1 1 2 ] what will be the output of the following statements?
(i) print (M[-2][1])
(ii) print (M[2][1])
(iii) print (M[2][-1]) ( iv) print (M[2][-1])
114. What will be the output of the following code ?
Copyright: Govind Vidyalaya Tamulia
29
def test_me(a):
a[0] = 'New value'
a[1] = a[1] + 1 args = ['Old value',99] test_me(args)
print (args[0], args[1])
115. Write the appropriate for statements for the following:
(i)
(ii)
(iii)
(iv)
Subscripted variable
I
A
X
S
1, 4, 7,
1, 3, 5,
5, 4, 3,
2, 4, 6,
10
7
2, 1
8, 10
Note :for loop expresions will change the values as given in second column in the above table.
116. Find out the syntactical errors in the following program :
Ch, Sch = 9, 90
if Ch <= 9 :
S = [2 2]
print("%d" %Ch) for x in range(1,3): for y in range(1, 3):
if (y == 0):
S = ["A"]
else
S = ["B"]
print (S)
117. Find out the syntactical errors in the following program :
x =[2, 3, 4, 5, 6]
z [2, 6, 4, 7, 9]
for i in range(0, 5)
x[i] = i
z[i] = i + 3 y= z
x=y
print(x[i])
print(z[i])
118. What will be the output of the following program segment
a = [6, 5, 4, 3, 2, 1]
for i in range(5,-1,-1):
print("a is :" , a[i])
119. What will be the output of the following program ?
a = [5, 10, 15, 20, 25]
k=1
i=a[1]+ 1
j = a[2] + 1
m = a[k + 1] print((i, j, m))
120. What will be the output of the following program ?
def string_func(str):
In = len(str)
for i in range(ln):
for j in range (i+1):
print (str[i], end=" ")
Copyright: Govind Vidyalaya Tamulia
30
print()
string_func("DELHI")
121. What will be the output of the following program ?
a = [1, 2, 3, 4. 5] for i in range(0, 5):
a[i] = 5 * i
for i in range(0, 5):
print(a[i])
122. What will be the output of the following program ?
b, c = 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
for a in range(0, 10):
if (a % 2 == 0):
b += c[a]
print(b, end=" ")
123. What will be the output of the following program ?
b, c = 0, [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
for a in range(0, 10):
b += c[a]
print(b, end=" ")
124. Identify error(s), if any, in the following program : sum[2, 4]
for i in range(0, 2)
for j in range(0, 3):
print("%d" %sum)
125. Identify error(s), if any, in the following program :
a = [0, 1, 8, 7, 6, 4]
for i in range(0,15):
print(a[i])
126. What will be the output of the following program segment ?
str = "aNDarIeL", .
nstr =
for i in range(len(str)):
if str[i].isupper():
nstr = nstr + str[i].lower()
else:
nstr = nstr + str[i].upper(),
print (nstr)
127. Identify error(s), if any, in the following program : sum = [6, 3]
sum = [1, 1]
()
print(sum)
128. What will be the output of the following program ?
b = [4, 6, 7, 4, 5, 12, 11, 10, 8, 17]
for I in range(1, 3):
for j in range(1 , 3):
b[I] = 4 * 1+ j
print(b[I])
129. Identify error(s), if any, in the following program :
MAX = '5'
list = (50, 40, 30, 20, 10)
Copyright: Govind Vidyalaya Tamulia
31
for Ctr in range(0, MAX)
print(list[Cti]
130. What will be the output of the following code ?
def test_me(a, b):
a = 'New value'
b=b+1
return a, b
x, y = 'Old value', 99 x, y = test_me(x, y) print (x, y)
1. Write a program to input total number or days and find to l number of months and remaining days after
months,
2. Write a program to calculate the volume and area of spher e. (Volume (4/3) * pie " and Area 4 *
r2
3. Write a program that gets 2 string variables and 2 number variables from the user, concatenates
(joins them together with no spaces) and displays the strings, then multiplies the two numbers MI a
new line.
4. What is the purpose of type conversion?
5. What is simple assignment and compound assignment?
6. The modulus operator works only with integersTrue or False.
7. Determine the error in the following statements:
(a) print ("hello ");
(b) a=2,b=5,c= 11; d=21
8. Write a program to read numl and num2 and store their sum in num3 and product in num4.
9. Write a program to find the maximum of two numbers using conditional operator.
10. Write a program to enter the time in minutes and print in the following format:
__________ Hours ________min
11. Write a program to form the area of a circle.
12. Write a program to calculate
(a) energy = m * g * h
2
(b) distance = u *t + 1/2 * a* t
(c) speed = distance / time
13. Write a program to find the area of a square.
14. Write a program to find the perimeter of a rectangle.
15. Write a Python program that inputs a student's marks obtained out of 600 and print the percentage of
marks.
16. Write a program to find the sum of two given numbers.
17. Write a program to find the sum, difference, multiplication and division between two nu
18. Write a program to find the simple interest of certain principal. The formula is : SI = (Principal *Rate *
Time) / 100
SI = Simple interest
Principal = Amount for which simple interest will be calculated
Copyright: Govind Vidyalaya Tamulia
32
19.
20.
21.
22.
23.
24.
25.
26.
27.
28.
29.
30.
33
41.
42.
43.
44.
45.
46.
47.
48.
1 to 5
6 to 10
more than 10
1
3.5
5.5
Write a program to calculate the late fee according to the number of days.
51. Write a program to input any 10 numbers and find their sum and average using for loop.
52. Write a program to print the mathematical tables from 1 to 10.
53. Write a program to input any number and print its digits in reverse order using while statement. The input number
must be positive.
54. Write a program to find the greatest common divisor of given two numbers.
55. Write a program to find smallest factor of a number.
56. Write a for loop which will produce the following output (Hint: Use two nested for loops).
1
22
333
444
55555
56. Write a program to print the following pattern using nested while loop :
1
12
123
1234
12345
57. Write a menu driven program to find the area of circle, rectangle, circumference of circle and area of square.
58. Write a program to input number in between 1 and 100 and guess either it is too low or too high. (Hints. Use
random function).
34
59. Write a menu driven program to perform mathematical calculation like addition, subtraction and
multiplication between two numbers using if...else if statements. The menu is as: Mathematical Calculation
1. For Addition
2. Subtraction
3. Multiplication
4. D i v i s i o n
60. Write a program to find the sum of series : 1 + x' /2! +x / 3 1 + ............ + xn / (n+1)!
61. Write a program to find greatest number between 'N' numbers.
62. Write a program to find the sum of following geometric series :
s = a + ar + ar 2 + ar 3 + ar4+ + arn
63. Write a program to find armstrong (like 153 = 13 + 53 + 33+ . . . + 3N) numbers upto N.
64. Write a program to accept monthly salary from the user, and display income tax with the he of
following rules :
MONTHLY SALARY
INCOME TAX
69000 or More
47500 68999
47499 or Less
64. For domestic consumption category, an electricity board charges according to following table:
Load
Upto 2 kw,
40/month
Upto >2-5 kw
Above 5 kw
100/month
20/kw/month
201-400
Units/pm
Above 400
Units/pm
3.70
3.70
3.70
5.50
5.50
5.50
6.50
6.50
6.50
Write a program to enter the sanctioned load and the number of units consumed and print out the monthly
charges.
65. Three natural numbers a, b and c are said to form a Pythagorean Triplet if c2= a2 + b2. Write a program to
find the Pythagorean triplets for integers from I to 20.
66. Write a program to input a number and print whether the number is a special number or not. (Note: A number
is said to be a special number, if the sum of the factorial of the digits of the number is same as the original
number, e.g., 145 is a special number, because 1! + 4! + 5! = 1 + 24 + 125 = 145)
67. Computech company has 15 employees who have been divided into four grades as per their basic pay as
follow :
GRADE I Basic245000 p.m. or more
D.A
40 % of Basic
1-I.R.A
30 % of Basic
GRADE II BasicZ 30000 p.m. or more but less than Z 45000
D.A
40 % of Basic
H.R.A : 25 % of Basic
GRADE III Basic : Less than Z 30000 but more than Z 15000
Copyright: Govind Vidyalaya Tamulia
35
D.A
: 30 % of Basic
H.R.A : 20 % of Basic GRADE IV Basic :
15000 p.m. or less
D.A
: 30 % of Basic
H.R.A : 15 % of Basic
If the salary, which is the total of Basic, D.A (Dearness Allowance) and H.R.A (House Rent Allowance), is
above 2100000 per annum, then Income Tax at the rate of 30% of the annual salary exceeding Z100000 is
deducted on monthly basis at source. Taking names of the employees and the basic (Monthly) pay as inputs,
a pay slip for each employee is to be printed. Write a program to perform this job.
68. A computerized ticket counter of an underground metro rail station charges for each ride at the following
rates :
AGE (in years)
AMOUNT/HEAD
18 or above
50
20
NIL
Marks(%)
Fail
0 34
Pass
35 59
Good
60 79
Very Good
80 and above
The output should display the categories and the corresponding frequencies. i.e., the number of students in
each category in two columns.
71. Write a program to accept a date (dd/mm/yyyy) and check for the validity of the date.
Chapter 6:-User-Defined Function in Python
72. Write a function to find the sum of natural numbers up to 'N'.
73. Write a function to find the result of (a + b)2.
74. Write a function to find the sum of all odd numbers unto 'N'.
75. Write a function to calculate GCD of two numbers using function.
76. Write a function to read the values of three coefficients of a quadratic equation :
Ax2+ Bx +C = 0
77. Find the roots of the equation and display them on the screen (including complex specifying the nature of
roots).
78. Write aerogram using function to print the Fibonacci series up to input limit.
79. Write a function to generate and print factorial numbers up to 'N' (provided by user).
80. Write a function that interchanges the value of two integers 'A' and 'B' without using any extra
variable.
81. Write a function which will accept the height of the person in inches and return the height in feet and
inches in two separate variables.
Copyright: Govind Vidyalaya Tamulia
36
82. Write a function to find the sum of series : 1 + 3 + 5 + 7 + 9 + 11 + ......... upto 'N' terms.
83. Write a function to find the total number of 0's and 5's in a given number.
84. Write a function to find the sum of series : 12 + 22 + 32 + 42 + 52 + 62 + upto 'N' terms.
85. Write a program using function to find the sum of all the prime numbers between 1 and 100. Also print
all the prime numbers between 1 and 100.
86. Write a program to find the sum of the following series : a + ar + ar2 +...+ ar(n-1)
87. Write a program using function which accepts any text or string and prints it in reverse order.
88. Write a function to find the sum of the following series :
1 + (1 + 2) + (1 + 2 + 3) + (1 + 2 + 3 + 4) + ........... +(1 +2+3 + 4 + . . + N)
89. Define a function called cabmeter_calculator(km) to calculate the bill for a customer according to the given
conditions :
Kilometer Travelled (km)
Fare/km(?)
<= 1 km
> 1 and <= 5 km
> 6 and <= 15 km
> 15 and <= 35 km
> 35 km
30
25
20
15
12
37
105. Write a program to accept the total sale of three products by three salesmen in a double
dimensional array. Calculate the total sale of each salesman and total sale of each product.
106. Write a user-defined function to display the sum of column elements of a two-dimensional list R[7][7]
containing integers.
107. Write a user-defined function to display the sum of row elements of a two-dimensional list R[5][6]
containing integers.
108. Write a user-defined function to display the product of row elements of two dimensional list A[4][6]
containing integers.
109. Write a user-defined function to display the product of column elements of a two-dimensional list R[4]
[4] containing integers.
110. Write a program to display the sum of left and right diagonals of 4 x4 matrix as given below:
11 12 23 24
15 14 17 28
19 10 11 12
13 14 15 16
Output :
Sum of diagonal left to right is : 52
Sum of diagonal right to left is : 64
111. Write a program to read the noonday temperature for each day of a month and then report the month's
average noonday temperature, as well as print hottest and coolest days of that month.
112. Write a program in Python to enter data given by the user into two 3 x 4 lists and find Sum of each element
and stored as another 3 x 4 list.
113. Write a function that checks for matching braces in an algebraic expression. If the match is successful,
function returns one (1) otherwise returns zero (0).
Chapter 2:-Working with Directories and Tuples
114. Write a program to create a dictionary called Friends by initializing six friends roll number as key and
name as value and print the dictionary's values only.
115. Write a program to create a dictionary Company to store company details like its name and internet address.
The company's name is treated as key and internet address as value. The program should ask user to enter
details according to user choice and display all the address of the company with company name.
116. In a school, there are 45 students in llth class. Each student has Rollno, Name, EngMarks, PhyMarks,
ChemMarks, Math Marks and Comp Marks. Write a program to calculate and print the total of marks and
percentage of marks for all students.
38
Maximum Marks: 70
General Instructions:
(i) All questions are compulsory.
(ii) Answer the questions after carefully reading the text.
39
(c) Find the output for the following : def myst(data):
for i in range(0, len(data)): Min = 0
for j in range(i+1, len(data)): if data[j] < data[Min]: Min = j
temp = data[Min] data[Min] = data[i] data[i] = temp
def main():
data = [10, -1, 4, 2]
myst(data)
for i in range(0, len(data)):
print(i, end=" ")
main()
(d) Find the output for the following : a = 6; b = 10; c = 2
a=a+4*( a -5)
b=a+4 //(b+5)+c
print ("The value of a is: %0.2f' % a)
print ("The value of b is: %0.2f' % b)
6. (a) Rewrite the following code using while loop :
def count(n):
ct = 0
for i in range(0, n):
if (random.random() < 0.5):
ct += 1
return et
(b) Find the syntax error(s), if any, in the following program :
NAME = "admiNStrAtiOn"
NewNAME = " "
for x in range(0, len(NAME)):
if islower():
NewNAME = NewNAME + NAME[y].upper()else:
if NAME[x].isuper:
if (x % 2 = 0):
NewNAME = NewNAME + NAME[x - 1]
else:
NewNAME = NewNAME + NAME[x]
print NewNAME
(c) Write a program to find the sum of all even numbers of a 3 x 3 matrix.
(d) Write a program to check whether a number is a prime number or not.
7. (a) Raising a number n to a power p is the same as multiplying n by itself p times. Write a function called
Power that takes two arguments, a double value for n and an int value for p and returns the result as
double value. Use default argument value 2 for p, so that if this argument is omitted the number will be
squared. Write the main() function that gets value from the user to test power function.
(b) Write a program to find the number of characters and words in a string inputted by the user. Assume
that different words are separated by a single space.
(c) Write a program to replace every space (" ") in a string with a hyphen H.