Ch-03: Programming Fundamentals - Short Question Answers | PDF
Ch-03: Programming Fundamentals - Short Question Answers | PDF
Chapter
03 Programming Fundamentals
SHORT QUESTION AND ANSWERS
1. Define computer program and programmer?
Ans: A set of well-defined instructions that can be executed by a computer to solve
problem is called computer program. A computer program is written in
programming language. A person who knows how to write computer program
correctly is called programmer.
2. How does a computer program interact with the user?
Ans: The program interacts with the user by accepting input, executing instruction
of a time and delivering the result.
3. Where is a program loaded during execution?
Ans: The program is loaded into the main memory during execution.
4. Compare the execution of an interactive program and a batch program.
Ans: An interactive program is a program that requires real-time input from a user
to work. The program responds to the commands as they are provided. On the
other hand, a batch program executes a series of pre-defined commands or
tasks without user interaction during execution. These programs are designed
to execute commands automatically in a sequence.
5. Give an example of batch program?
Ans: An example of a batch program is the print jobs on a printer that line up in a
queue and are processed one by one without requiring user interaction once
the queue is set. The process stops when no more jobs are in the queue.
6. What is the use of programming language? Give three examples of
programming languages?
Ans: The programming languages are used to write computer programs. A
programming language defines the rules for writing the computer programs. A
large number of programming languages are available for writing programs.
Three examples of programming languages are Java, Python and C++.
7. What is syntax?
1|P age
Computer Science Class-11
2|P age
Computer Science Class-11
3|P age
Computer Science Class-11
Ans: Data scientists frequently use Python because it has a large number of tools and
packages for machine learning and Artificial Intelligence.
23. How is Python used in data analysis and visualization? Give example.
Ans: Python is widely used in data analysis and visualization as it provides powerful
tools to analyze data and create informative charts and graphs. For example,
Netflix uses Python to analyze user data and recommend shows or moves to
watch. An example of data visualization using Python is creating a bar chart to
sales of different products over a month.
24. Give two examples of natural language processing.
Ans: An example of natural language processing is to give command to Google Home
Assistant such as “OK Google, play my favorite playlist”. Another common
example of NLP is chatbots used by customer service on the websites.
25. What is IDE?
Ans: A software that provides a programming environment for programmers to
write and execute computer programs is known as Integrated Development
Environment (IDE). An IDE consists of different tools to help the programmer to
write, execute and test computer programs. These tools include text editors,
compilers/interpreters and debuggers.
26. What is the purpose of the interactive console in Python IDEs?
Ans: The interactive console in Python IDEs allows users to execute commands
directly and see the results immediately. It makes it easier to test and debug
code.
27. Name an online Python IDE and its primary feature.
Ans: An online Python IDE is Replit. It provides an interactive console and an easy-
to-use environment suitable for beginners.
28. What is a REPL in the context of Replit and how is it created?
Ans: A REPL (Read-Eval-Print-Loop) in Replit is an interactive programming
environment that is used to write, evaluate and execute code. It is created by
pressing the ‘Crate Repl’ button after logging into Replit.
29. Define keyword and give three examples.
Ans: Keyword has a predefined meaning and purpose in a programming language.
The meaning and purpose of a keyword is defined by the developer of the
4|P age
Computer Science Class-11
language. It can be used for some purpose for which it is defined. Three
examples of keywords are if, for and in.
30. Can the reserved words be used as variable names in Python?
Ans: No, the reserved words cannot be used as variable names in python because
they have predefined meanings.
31. What are comments? Where can comments be added in the program?
Ans: Comments are the lines of text in the program that are not executed by Python
interpreter. The comments are usually written to describe the code in natural
language such as English. The comments can be added any where in the
program.
32. Write two purpose of writing comments in the program.
Ans: Firstly, the comments allow other programmers to understand the code easily.
Secondly, the comments are notes about the code that explain its purpose. It
helps in understanding the program even after a long time.
33. What is variable? Why is it used in programs?
Ans: A variable is a named memory location. It is used to store program’s input data
and its computational results during execution. The value of variable may
change during the execution of the program. However, the name of variable
cannot be changed.
34. Write any four rules for declaring variables in Python?
Ans: The first character of variable must be a letter or underscore. The blank spaces
are not allowed in variable names. The reserved words cannot be used as
variable names. The special symbols such as % and @ cannot be used as variable
name.
35. Give any five examples of valid variable names.
Ans: Income _area total_price MaX_SPEED Marks1
36. State whether the variable names are valid or invalid? Give reason for invalid
name?
Ans: a. Age Valid
b. Int Invalid. A keyword cannot be used as variable name.
c. -on-off Invalid. A variable cannot have hyphen in it.
d. This-I Invalid. A variable cannot have hyphen in it.
5|P age
Computer Science Class-11
6|P age
Computer Science Class-11
7|P age
Computer Science Class-11
50. List the types of operators used in Python. Write briefly about any two of
them with examples.
Ans: Three types of operators in Python are arithmetic, relational and logical
operators. The arithmetic opertors are used to perform the mathematical
operation on data. Some examples of arithmetic operators are +, -, *, / and %.
The relational operators are used to compare two values and produce result as
true or false. Some examples of relational operators are >, <, <=, <=, == and !=.
51. What does the modulus operator (%) do in Python? Give example.
Ans: The modulus operator (%) returns remainder of a division.
For example: 5 % 4 will return 1.
52. What is the purpose of the integer division operator (//) in Python? Give
example.
Ans: The integer division operator (//) returns only the integral part of a division. It
discards any decimal part. For example, 5 // 4 will return 1.
53. How is exponentiation performed in Python, and what is the symbol for it?
Give example.
Ans: Exponentiation in Python is performed using ** operator. For example 2 ** 3
will return 8 that is 2 raised to the power 3.
54. What is a logical bug in Python, and how can it be detected?
Ans: A logical bug in Python is a logical error in the code that produces incorrect
results. The syntax of the code may be correct but it does not behave according
to the expectation due to the logical mistake. Logical errors usually do not crash
the program and are hard to detect.
55. How a dry-run can help to identify logical bugs in a code snippet?
Ans: The dry-run is the simplest method to detect a logical bug in the code. It is used
to execute the program on paper and keep track of the variables for each line
of the code.
56. Give the following code, what will be the final values of x and y after
execution?
Ans: x = 10
y = 20
temp = x
8|P age
Computer Science Class-11
x=y
y = temp
After execution, the value of x will be 20 and the value of y will be 10.
57. How can the assignment operator be combined with arithmetic operators in
Python?
Ans: The assignment operator can be combined with arithmetic operators to update
the value of a variable. For example, i = i + 1 can be written as i += 1,
i = i -2 as i -= 2 and i = i * 3 as i *= 3
58. What is meant by operation precedence? What is the order of operator
precedence in Python for arithmetic operations?
Ans: The order in which different types of operators in an expression are evaluation
is known as operator precedence. It is also known as hierarchy of operators.
Each operator has its own precedence level. If an expression contains different
types of operators, the operators with higher precedence are evaluated before
the operators with lower precedence. The order of precedence of arithmetic
operators are **, *, /, //, %, +, -.
59. Differentiate between assignment operator (=) and equal to operator (==).
Ans: The symbol = is an assignment operator that assigns a value to a variable. The
symbol == is a relational operator that checks if two values are equal or not.
60. What are logical operators in Python? Give examples.
Ans: The logical operators are used to combine multiple conditions or reverse a
condition. Python provides three logical operators called and operator, or
operator and not operator. Some examples are (a<50) and (b>50),
(x<50)or(y<90) and not(a>b)
61. What is the use of “and” operator? Give example.
Ans: The and operator is used to form a compound condition in which two condition
are evaluated. The conditions are given using comparison operators. The
compound condition returns true if both conditions are true. It returns false if
any one condition is false. An example of OR operator is (A>50) or (B>10)
62. What is the use of “or” operator? Give example.
Ans: The or operator is used to form a compound condition in which two conditions
are evaluated. The conditions are given using comparison operators. The
9|P age
Computer Science Class-11
compound condition returns true if any condition is true. It returns false if both
conditions are false. An example of OR operator is (A>50) or (B>50)
63. What is the use of “not” operator?
Ans: The not operator is used with single condition. It is used to reverse the result of
condition. It returns true if the condition is false and returns false if the
condition is true. An example of an operator is not (A==B).
64. Differentiate between relational and logical operators. No need to change.
Ans: The relational operators compare two values and produce result as true or false.
The logical operators combine multiple conditions or reverse a condition. The
number of relational operators is six and the number of logical operators is
three.
65. Why do we need conditional statement?
Ans: A conditional statement is needed to make decisions in programming based on
a condition. It executes a statement if the condition is true and ignore when the
condition is false. For example, a conditional statement may display “Pass” if
the marks of a student are 33 or more.
66. Describe a condition with an example.
Ans: A condition is an expression that is either true or false. A condition may consist
of arithmetic expressions, relational expressions and logical expressions. An
example of a condition is a > b that will check if the value of a is greater than b.
67. Write the structure of if statement with brief description
Ans: The structure of if statement is as follows:
if condition;
statement
The word is the keyword that represents the if statement. The given condition
will be checked and can be true or false. The statement will be executed if the
condition is true, it must be written with an indentation by pressing tab key
before the statement.
68. Differentiate between if statement and if-else statement with an example.
Ans: If statement is used to execute or skip a statement or set of statements based
on a condition. The statement is executed if condition is true. Otherwise, it is
skipped. For example:
10 | P a g e
Computer Science Class-11
11 | P a g e
Computer Science Class-11
Ans: Loops are important in programming languages. Firstly, they are used to repeat
a statement or set of statements repeatedly without writing the statements
again and again. Secondly, they save time and effort. Thirdly, the size of the
program is reduced using loops.
74. Describe the basic syntax of a for loop in Python.
Ans: The basic syntax of for loop in Python is as follows:
For var in (value1, value2, value3…);
statement
in the above syntax, for is the keyword that indicates the for loop. var indicates
the name of a variable used with for loop. in indicates the keyword before the
list of values. values indicates the number of times for loop will execute.
Statement indicates the statement or set of statement that will be executed by
for loop.
75. How does the range() function work in a for loop?
Ans: The range() function generates a sequence of number for the loop. It can take
one, two or three arguments as follows:
range(stop): it starts from 0 and ends at stop-1 and increment by 1.
range(start, stop): It starts from start and ends at stop-1 and increments by 1.
range(start, stop, step): It starts from start, ends at stop-1 and increment by
step.
76. Why indentation is crucial in a loop?
Ans: Indentation in Python is crucial for defining the structure of loop. It indicates
the statements that are part of the loop body. Proper indentation ensures that
the code block associated with the loop executes correctly. The wrong use of
indentation will lead to incorrect code structure and execution errors.
77. What happens if you forget to indent the code block after for loop?
Ans: A syntax error occurs if you forget to indent the code block after the loop.
Python will display an error message on the screen.
78. What is a list in Python?
Ans: A list is a type of variable in Python that can store multiple values. each item
stored in a list is called an element. Lists can store elements of different data
types including integers, floats and strings etc.
12 | P a g e
Computer Science Class-11
13 | P a g e
Computer Science Class-11
print(sum(test))
86. How an element can be inserted into a list? Give an example.
Ans: An element can be inserted into a list using insert() method. For example:
test = [1, 2, 3]
test.insert(1, 10)
print(test) # Output: [1, 10, 2, 3]
87. What does the Index() method to do in a list?
Ans: The index() method returns the index of the first occurrence of a specified value
in the list.
For example:
test = [1, 2, 3, 2]
print(test.index(2))
88. How would you add the number 100 to the end of a list and then print the
updated list?
Ans: test = [10, 20, 30]
test.append(100)
print(test)
89. How do you check if an element exists in a list? Give an example.
Ans: You can check if an element exists in a list using the in membership operator.
For example:
test = [1, 2, 3, 4]
print(3 in test)
print(5 in test)
90. How do you know about turtle graphics
Ans: Turtle graphics is a Python that can be used to create basic graphics and
drawings. It also provides advanced features for creating animations.
Simulations and computer games. The turtle refers to a virtual drawing tool that
moves on the canvas. The canvas is like a drawing board where the turtle moves
and draws.
91. What function is used to load the canvas in Turtle Graphics?
Ans: The function used to load the canvas in Turtle Graphics is turtle.screen().
14 | P a g e
Computer Science Class-11
92. How the background color of the Turtle Graphics canvas can be changed?
Ans: The background color of Turtle Graphics canvas can be changed using
turtle.bgcolor() function:
turtle.bgcolor(“lightblue”)
93. What junction is used to change the color of the pen in Turtle Graphics?
Ans: The turtle.color() function is used to change the color of the pen in Turtle
Graphics.
94. How can you move the turtle without drawing a line?
Ans: The penup() function is used to move the pen up from the canvas so it does not
draw a line when the pen moves.
95. Write the code to draw a red circle with a radius of 50 pixels in Turtle
Graphics?
Ans: import.turtle
turtle.color(“red”)
turtle.circle(50)
96. What does the forward() function do in Turtle Graphics? Give an example.
Ans: The forward() function is used to move the turtle forward by a specified
distance towards its current direction as follows:
turtle.forward(100)
97. Which function can be used to rotate the turtle to the right by 90 degrees?
Ans: The turtle.right(90) function can be used to rotate the turtle to the right by 90
degrees.
98. Which function is used to clear the canvas in Turtle Graphics?
Ans: The turtle.reset() function is used to clear the canvas and reset the turtle to its
starting position.
99. What is a library? How is a library imported in Python program?
Ans: A library is a pre-written set of code that can be used in the programs. A library
may consist of many functions to perform different tasks. These functions can
be used by importing the required library to the program. The predefined
functions help in writing the program quickly and easily. A library can be
imported in Python program using import statement such as import datetime.
15 | P a g e
Computer Science Class-11
16 | P a g e
Computer Science Class-11
17 | P a g e
Computer Science Class-11
Ans:
115.
Ans:
116.
Ans:
117.
Ans:
118.
Ans:
119.
Ans:
120.
Ans:
121.
Ans:
122.
Ans:
123.
Ans:
124.
Ans:
125.
Ans:
126.
Ans:
127.
Ans:
128.
18 | P a g e
Computer Science Class-11
Ans:
129.
Ans:
130.
Ans:
131.
Ans:
132.
Ans:
133.
Ans:
134.
Ans:
135.
Ans:
136.
Ans:
137.
Ans:
138.
Ans:
139.
Ans:
140.
Ans:
141.
Ans:
142.
19 | P a g e
Computer Science Class-11
Ans:
143.
Ans:
144.
Ans:
145.
Ans:
146.
Ans:
147.
Ans:
148.
Ans:
149.
Ans:
150.
Ans:
151.
Ans:
152.
Ans:
153.
Ans:
154.
Ans:
155.
Ans:
156.
20 | P a g e
Computer Science Class-11
Ans:
157.
Ans:
158.
Ans:
159.
Ans:
160.
Ans:
161.
Ans:
162.
Ans:
163.
Ans:
164.
Ans:
165.
Ans:
166.
Ans:
167.
Ans:
168.
Ans:
169.
Ans:
170.
21 | P a g e
Computer Science Class-11
Ans:
171.
Ans:
172.
Ans:
173.
Ans:
174.
Ans:
175.
Ans:
176.
Ans:
177.
Ans:
178.
Ans:
179.
Ans:
180.
Ans:
181.
Ans:
182.
Ans:
183.
Ans:
184.
22 | P a g e
Computer Science Class-11
Ans:
185.
Ans:
186.
Ans:
187.
Ans:
188.
Ans:
189.
Ans:
190.
Ans:
191.
Ans:
192.
Ans:
193.
Ans:
194.
Ans:
195.
Ans:
196.
Ans:
197.
Ans:
198.
23 | P a g e
Computer Science Class-11
Ans:
199.
Ans:
200.
Ans:
201.
Ans:
202.
Ans:
203.
Ans:
204.
Ans:
205.
Ans:
206.
Ans:
207.
Ans:
208.
Ans:
209.
Ans:
210.
Ans:
211.
Ans:
212.
24 | P a g e
Computer Science Class-11
Ans:
213.
Ans:
214.
Ans:
215.
Ans:
216.
Ans:
217.
Ans:
218.
Ans:
219.
Ans:
220.
Ans:
221.
Ans:
222.
Ans:
223.
Ans:
224.
Ans:
225.
Ans:
226.
25 | P a g e
Computer Science Class-11
Ans:
227.
Ans:
228.
Ans:
229.
Ans:
230.
Ans:
231.
Ans:
232.
Ans:
233.
Ans:
234.
Ans:
235.
Ans:
236.
Ans:
237.
Ans:
238.
Ans:
239.
Ans:
240.
26 | P a g e
Computer Science Class-11
Ans:
241.
Ans:
242.
Ans:
243.
Ans:
244.
Ans:
245.
Ans:
246.
Ans:
247.
Ans:
248.
Ans:
249.
Ans:
250.
Ans:
27 | P a g e