Problem Solving and Programming 1 Flashcards

1
Q

What is a variable in programming?

A

A variable is a container that holds a value or data that can be changed during program execution.

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

What is the difference between an integer and a float?

A

An integer is a whole number, while a float is a number that includes a decimal point.

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

What is the purpose of the “if” statement in programming?

A

An “if” statement allows you to execute certain code only if a specified condition is true.

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

What is a loop in programming?

A

A loop is a programming construct that repeats a block of code multiple times based on a condition.

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

What is the difference between a “for” loop and a “while” loop?

A

A “for” loop repeats a block of code a set number of times, while a “while” loop repeats as long as a given condition is true.

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

What is an algorithm in computer science?

A

An algorithm is a step-by-step procedure for solving a problem or performing a task.

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

What is the purpose of a function in programming?

A

A function is a reusable block of code that performs a specific task, making the program more modular and easier to maintain.

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

What is a parameter in a function?

A

A parameter is a variable in a function definition that receives a value when the function is called.

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

What is a return value in a function?

A

A return value is the result that a function gives back after performing its task, often used to send data back to the calling code.

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

What is debugging?

A

Debugging is the process of identifying and fixing errors or bugs in the code to ensure the program runs as expected.

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

What is a syntax error?

A

A syntax error occurs when the code violates the rules of the programming language, such as missing parentheses or a misplaced semicolon.

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

What is a logical error in programming?

A

A logical error happens when the code runs without crashing but produces incorrect results due to a flaw in the logic.

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

What is a “while” loop used for?

A

A “while” loop is used to repeat a block of code as long as a specified condition remains true.

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

What is a list in programming?

A

A list is an ordered collection of items, which can be of different data types, and is often used to store multiple values.

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

How do you access an item in a list in Python?

A

You access an item in a list using its index, starting from 0.
Example: my_list[0] accesses the first item.

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

What is an array?

A

An array is a data structure that stores multiple items of the same data type in contiguous memory locations.

17
Q

What is the difference between a list and an array?

A

A list is more flexible and can store different data types, while an array stores only the same data type and is often more efficient for large amounts of data.

18
Q

What does the “continue” statement do in a loop?

A

The “continue” statement skips the current iteration of the loop and moves to the next one.

19
Q

What is the purpose of the “break” statement in loops?

A

The “break” statement terminates the loop immediately and exits the loop, regardless of the loop’s condition.

20
Q

What is the difference between a “global” and “local” variable?

A

A global variable is declared outside of a function and can be accessed anywhere in the program, while a local variable is declared inside a function and can only be accessed within that function.

21
Q

What is a string in programming?

A

A string is a sequence of characters, such as text, enclosed in quotation marks.

22
Q

How do you concatenate two strings in Python?

A

You concatenate strings using the + operator.
Example: “Hello” + “ “ + “World” results in “Hello World”.

23
Q

What is a conditional expression?

A

A conditional expression is an expression that evaluates to one of two values depending on whether a condition is true or false.

24
Q

What is the purpose of the “else” clause in an “if” statement?

A

The “else” clause specifies code to execute if the condition in the “if” statement is false.

25
Q

What is the difference between “==” and “=” in programming?

A

”==” is a comparison operator that checks if two values are equal, while “=” is an assignment operator used to assign a value to a variable.

26
Q

What is a nested loop?

A

A nested loop is a loop inside another loop, used for iterating through multidimensional data structures like matrices.

27
Q

What is an infinite loop?

A

An infinite loop occurs when a loop’s condition is always true, causing it to run endlessly unless externally stopped.

28
Q

What does “try” and “except” do in Python?

A

“try” allows you to execute code that may raise an error, while “except” lets you handle the error without stopping the program.

29
Q

What is a comment in programming?

A

A comment is a non-executable line of code used to add notes or explanations for others or yourself.

30
Q

How do you write a single-line comment in Python?

A

You use the # symbol.
Example: # This is a comment.

31
Q

What is the difference between “==” and “is” in Python?

A

”==” compares values, while “is” checks if two variables point to the same object in memory.

32
Q

What is a method in programming?

A

A method is a function that is associated with an object and performs an action on that object.

33
Q

What is the purpose of the “len()” function in Python?

A

The “len()” function returns the number of items (length) in a list, string, or other iterable.

34
Q

What is a tuple?

A

A tuple is an ordered, immutable collection of items, often used to store multiple values that should not change.

35
Q

How is a tuple different from a list?

A

A tuple is immutable (cannot be modified), while a list is mutable (can be changed).

36
Q

What is the difference between “and” and “or” in Boolean expressions?

A

“and” returns True if both conditions are true, while “or” returns True if at least one condition is true.

37
Q

What is an exception in programming?

A

An exception is an error that occurs during program execution, which can be handled to prevent the program from crashing.