CT3/P3 Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What are the types of programming constructs?

A

Sequence
Selection
Iteration

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is the function of a sequence programming construct?

A

It is used for the execution of statements or functions one after the other.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the function of a selection programming construct?

A

Selection is used to execute only a particular set of statements if a condition is satisfied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the function of an iteration programming construct?

A

Iteration is used to execute a particular set of statements repeatedly until a condition is satisfied.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

In what ways can iteration statements be created?

A

By counting how many times the statements are to be executed
By repeatedly executing the statements until a condition is true
By repeatedly executing the statements while a condition is true

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What structure is used to count the number of times a statement is to be executed?

A

“for” structure

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What structure is used to execute statements until a condition is met ?

A

“Repeat until” or “Do while” loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What structure is used to execute statements while a condition is met?

A

“While” loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What iteration structures are available in Python?

A

‘for’ loop and while loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What type of programming construct is used to print a multiplication table?

A

Iteration. For loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is the syntax for checking multiple conditions in Python?

A

if expression1:
statement(s)
elif expression2:
statements(s)

else:
statement(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is the syntax for ‘for’ loop in Python?

A

for num in range( , ):
statement(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is the syntax for while loop in Python?

A

while (condition):
statement(s)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What is a break statement used for?

A

Break statement in Python terminates the current loop and resumes operation from the next statement.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What are variables?

A

Variables are labels that are used to represent values stored in computer memory, whose values can be changed during the execution of a program.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are Constants?

A

Constants are labels that are used to represent values stored in computer memory that remain unchanged during the execution of a program.

17
Q

Why is declaration of variables important in programming?

A

Declaration of variables in a program is important because the correct amount of space in memory is allocated by the compiler.

18
Q

Why is it important to initialise a variable or constant?

A

It is important to initialise a variable or constant to avoid usage of previously stored values in a location. Not initialising a variable may result in wrong answers.

19
Q

How are values assigned to variables in Python?

A

In Python programming language, the variables are assigned when the first data is entered to it. The variables are typecast by using commands such as float, int or str to make them a floating-point, integer or string value.

20
Q

State an example for a typecasting statement.

A

length = int(input(‘Enter the length: ‘))

21
Q

What is the difference between integers and real numbers?

A

Integers are positive or negative whole numbers. Whereas positive or negative numbers that allow decimals and fractions are called real numbers.

22
Q

What is the output for the following program?
int_num = int(62) float_num=float(62) print(“integer num= “,int_num)
print(“float num= “,float_num)

A

integer num=62
float num=62.0