INFO1110 Foundation Code Review

0.0(0)
studied byStudied by 0 people
0.0(0)
full-widthCall Kai
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
GameKnowt Play
Card Sorting

1/64

encourage image

There's no tags or description

Looks like no tags are added yet.

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

65 Terms

1
New cards

"What is a function in Python?"

"A reusable block of code that performs a specific task. It is defined using def and can take inputs (parameters) and return outputs."

2
New cards

"What does a return statement do?"

"It exits a function and optionally sends a value back to the caller."

3
New cards

"What are parameters in a Python function?"

"Variables listed inside the parentheses in a function definition that receive values when the function is called."

4
New cards

"What are arguments?"

"The actual values passed to a function's parameters when it is called."

5
New cards

"What are type hints in Python?"

"Optional annotations that indicate expected data types for readability and type checking tools like mypy. They are not enforced at runtime."

6
New cards

"What is the purpose of the colon (:) after a function definition line?"

"It starts the function block — Python uses indentation instead of braces to define scope."

7
New cards

"What is indentation used for in Python?"

"To define blocks of code such as function bodies, loops, and conditionals. Incorrect indentation causes errors."

8
New cards

"What is a dictionary in Python?"

"An unordered collection of key–value pairs where each key must be unique."

9
New cards

"What happens if a dictionary key already exists and you assign it a new value?"

"The old value is overwritten — keys are unique."

10
New cards

"What happens if you assign a new key to a dictionary?"

"Python creates a new key–value pair automatically."

11
New cards

"What are lists in Python?"

"Ordered, mutable collections of items that can hold different data types."

12
New cards

"What are sets in Python?"

"Unordered collections of unique items — duplicates are automatically removed."

13
New cards

"What are tuples in Python?"

"Ordered, immutable sequences of values."

14
New cards

"What does list.append(x) do?"

"Adds item x to the end of the list."

15
New cards

"What does len() do?"

"Returns the number of items in a sequence or collection."

16
New cards

"What does `split(',')` do on a string?"

"Splits the string into parts using a comma as the separator and returns a list of substrings."

17
New cards

"What does .strip() do?"

"Removes whitespace or specified characters from the start and end of a string, but not spaces in the middle."

18
New cards

"What does .lower() do?"

"Returns a lowercase version of the string."

19
New cards

"What does .upper() do?"

"Returns an uppercase version of the string."

20
New cards

"What does .isdigit() check?"

"Returns True if all characters in the string are digits."

21
New cards

"What does .isalpha() check?"

"Returns True if all characters in the string are letters."

22
New cards

"What does .isupper() check?"

"Returns True if all letters in the string are uppercase."

23
New cards

"What does `with open(filename, 'r') as file:` do?”

"Opens a file for reading using a context manager, ensuring it closes automatically after use."

24
New cards

"What does file.readline() do?"

"Reads one line from a text file."

25
New cards

"What does for line in file: do?"

"Iterates over each line in the file one by one."

26
New cards

"What does int(input('Enter a number: ')) do?"

"Prompts the user for input, converts the input string to an integer."

27
New cards

"What does print() do?"

"Displays text or variables to the console."

28
New cards

"What does input() do?"

"Pauses program execution to receive text input from the user as a string."

29
New cards

"What is a Boolean value?"

"A value that is either True or False."

30
New cards

"What are comparison operators in Python?"

"Operators used to compare values: ==, !=, <, >, <=, >=."

31
New cards

"What are logical operators in Python?"

"Operators that combine Boolean expressions: and, or, not."

32
New cards

"What does and return?"

"True only if both conditions are True."

33
New cards

"What does or return?"

"True if at least one condition is True."

34
New cards

"What does not do?"

"Inverts a Boolean value (True becomes False, False becomes True)”

35
New cards

"What does if do in Python?"

"Executes code only if a condition is True."

36
New cards

"What does elif mean?"

"Short for 'else if' — checks another condition if the previous one was False."

37
New cards

"What does else do?"

"Specifies a block of code to run if none of the previous conditions are True."

38
New cards

"What does while do?"

"Repeats code as long as a condition is True."

39
New cards

"What does for do?"

"Iterates over each item in a sequence like a list, string, or range.”

40
New cards

"What does continue do in a loop?"

"Skips the rest of the current iteration and goes to the next one."

41
New cards

"What does break do in a loop?"

"Exits the loop immediately

42
New cards

"What is a flag variable?"

"A variable (often Boolean) used to track whether a certain condition has been met."

43
New cards

"What is an infinite loop?"

"A loop that never ends because its condition always remains True (e.g., while True:)."

44
New cards

"What does try and except do?"

"Used to handle exceptions (errors) gracefully, preventing the program from crashing.”

45
New cards

"What is FileNotFoundError?"

"An error that occurs when trying to open a file that doesn’t exist."

46
New cards

"What does except Exception: do?"

"Catches any kind of error that wasn’t specifically handled."

47
New cards

"What does exit() do?"

"Stops program execution immediately."

48
New cards

"What does += do?"

"Adds a value to a variable and stores the result in the same variable (e.g.

49
New cards

"What does * do when used with strings (e.g.'=' * 50)?"

“Creates a string made up of 50 equal signs."

50
New cards

"What is the difference between = and ==?"

"= assigns a value; == compares two values for equality."

51
New cards

"What does time * focus represent in an expression?"

"It multiplies two numeric values — often used for calculations like scores or totals."

52
New cards

"What is a float in Python?"

"A number that has a decimal point

53
New cards

"What is an integer in Python?"

"A whole number without a decimal point

54
New cards

"What is the purpose of indentation in loops and conditionals?"

"To indicate which statements belong to the block "

55
New cards

"What happens if indentation is inconsistent in Python?"

"It raises an IndentationError."

56
New cards

"What does range(5) generate?"

"A sequence of numbers from 0 up to (but not including) 5."

57
New cards

"What is the purpose of comments (lines starting with #)?"

"They explain code to humans and are ignored by Python when running."

58
New cards

"What is the purpose of separating logic into functions?"

"It improves readability, reusability, and organization of code.”

59
New cards

"What is the difference between mutable and immutable data types?"

"Mutable types (like lists and dicts) can be changed after creation; immutable types (like strings and tuples) cannot."

60
New cards

"What happens when you pass a dictionary to a function and modify it inside?"

"The changes affect the original dictionary because it’s mutable and passed by reference."

61
New cards

"What is the in operator used for?"

"Checks if a value exists in a sequence (like a list

62
New cards

"What does .append() do for lists?"

"Adds an element to the end of the list."

63
New cards

"What is the purpose of get() in dictionaries?"

"Retrieves the value of a key if it exists

64
New cards

"What is the general purpose of using functions and loops together?"

"To organize repeated tasks and automate data processing efficiently."

65
New cards

"What does it mean when Python is 'dynamically typed'?"

"Variables don’t have fixed types — their type can change at runtime based on the value assigned."