Topic 8 Flashcards

1
Q

What is a program?

A

A set of instructions that a computer follows to perform a task.

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

What is programming?

A

The process of writing instructions for a computer to execute.

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

What are the elements of programming?

A
  • Variables
  • Constants
  • Data types
  • Operators
  • Control structures
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Why is programming important?

A

It enables the creation of software applications that drive technology.

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

What would the world look like without programming?

A

Limited technology and automation; reliance on manual processes.

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

What is the first program typically written in Python?

A

print(“Hello world”)

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

What is a variable in programming?

A

A storage location identified by a name that holds a value.

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

What are the basic data types in Python?

A
  • INTEGER
  • FLOAT
  • STRING
  • BOOLEAN
  • DATE
  • CHARACTER
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the command ‘print(“hello”, “how”, “are”, “you”)’ do?

A

Prints the words with spaces in between.

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

How do you take string input in Python?

A

name=input(“What is your name?”)

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

What is a conditional statement?

A

A statement that executes different actions based on whether a condition is true or false.

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

What is the structure of an IF statement?

A

IF <condition> THEN <action> ELSE <alternative></alternative></action></condition>

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

What is the purpose of the ‘else’ clause in conditional statements?

A

To define an alternative action when the condition is false.

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

What does the ‘==’ operator do?

A

Checks if two values are equal.

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

Fill in the blank: In Python, __________ is used to check if a value is not equal to another value.

A

!=

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

What is the difference between a while loop and a repeat until loop?

A

While loop checks the condition before executing; repeat until checks after.

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

What is the syntax for a for loop in Python?

A

for i in range(start, end):

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

What is the purpose of the ‘break’ statement in loops?

A

To exit the loop prematurely.

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

What is iteration?

A

The process of executing a set of statements repeatedly.

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

What is a pre-condition loop?

A

A loop where the condition is tested before executing the loop body.

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

What is a post-condition loop?

A

A loop where the condition is tested after executing the loop body.

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

What does the modulus operator (%) do?

A

Returns the remainder of a division operation.

23
Q

Fill in the blank: In Python, __________ is used to create a loop that iterates a specific number of times.

24
Q

What is selection in programming?

A

The process of choosing which action to perform based on conditions.

25
What is an example of a sequence in programming?
The order of operations in a program that must be followed.
26
True or False: A while loop can run zero times.
True
27
True or False: A repeat until loop will always execute at least once.
True
28
What is the purpose of the 'elif' statement?
To check multiple conditions in a conditional structure.
29
What does the following code do? 'if(a > b and a > c):'
Checks if 'a' is greater than both 'b' and 'c'.
30
What is the output of '10 % 2'?
0
31
What does the 'case' structure allow in programming?
To execute one out of several branches based on the value of a variable.
32
What is a count-controlled loop?
A loop where you know beforehand how many times it should run.
33
What is the pseudocode structure for a count-controlled loop?
FOR a← 0 to 4 OUTPUT “Hello” ENDFOR
34
What is the maximum limit inclusion difference between pseudocode and Python?
In pseudocode, the maximum limit is included, while in Python it is excluded.
35
Fill in the blank: A _______ is executed at least 0 or more times.
Pre-Condition
36
What is string handling?
The process of manipulating strings, including finding length and extracting characters.
37
How do you find the length of a string in Python?
Use the len() function.
38
What does the expression city[0] return if city = 'Kathmandu'?
K
39
What does the expression city[0:3] return if city = 'Kathmandu'?
Kat
40
True or False: A procedure is the same as a function.
False
41
What are local and global variables?
Local variables are defined within a function, while global variables are defined outside and accessible throughout the program.
42
What is an array?
A collection of variables of the same datatype.
43
Why was there a need for an array?
To maintain large sets of data under a single variable name to avoid confusion.
44
How does Python implement arrays?
Using lists, which allow multiple data types.
45
What is a one-dimensional array?
An array with a single row of elements.
46
Give an example of a two-dimensional array.
studentsInfo=[[12,15,14],[14,12,17]]
47
Fill in the blank: To declare an empty list in Python for storing salaries of 100 players, use _______.
salaries = [None]*100
48
What does the index value represent in a list?
The position of elements in a list.
49
How can you add elements to an empty list in Python?
By using a loop to append marks or values.
50
What is the structure for a two-dimensional array declaration?
Creates Columns and Rows.
51
What operation can be performed on a 2D array to print data one by one?
Iterate through the array using nested loops.
52
What is the output of print(city[3:]) if city = 'Kathmandu'?
mandu
53
What are the two types of arrays mentioned?
* One dimensional array * Two dimensional array
54
What is the purpose of using meaningful identifiers in programming?
To enhance code readability and maintainability.