


Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!



Question: Which symbol begins a single-line comment in Python? // (double forward slash) # (pound symbol) * (asterisk) % (percent symbol)
Answer: # (pound symbol)
Question: Which data type is the value 3.14 in Python? Integer Float String Boolean
Answer: Float
Question: Which type of loop is designed for iterating a specific number of times? while loop for loop infinite loop do-while loop
Answer: for loop
Question: Which components are required in every Python while loop? A condition and an indented code block A variable and a return statement A counter and a break statement An iterator and a list
Answer: A condition and an indented code block
Question: Which keyword is used to exit a loop prematurely in Python? return break stop end
Answer: break
Question: In the code for item in my_list:, what does item represent? The index of the current element The current element being processed The length of the list The entire list
Answer: The current element being processed
Question: Which Python data structure automatically prevents duplicate values from being stored? List Tuple Dictionary Set
Answer: Set
Question: What must a developer do to run Python code written in a text editor? Save the file and use a Python interpreter. Press a run button within the editor. Upload the code to a web server. Convert the code to machine language first.
Answer: Save the file and use a Python interpreter.
Question: What advantage does an integrated terminal provide compared to using a separate terminal application? Faster code execution speed Access to additional Python libraries Eliminates need to switch between applications Automatic syntax error detection
Answer: Eliminates need to switch between applications
Question: Which action allows a Python script located in a different folder to be executed in the terminal? Use the edit command to open the script first Move the script to your desktop Use the cd command to navigate to the script's directory Rename the script to match the terminal's path
Answer: Use the cd command to navigate to the script's directory
Question: Which terminal command is used to navigate to a different directory before running a Python script? move goto cd nav
Answer: cd
Question: Which tool is used to execute Python code line-by-line interactively within a terminal? Python shell Text editor File explorer Debugger
Answer: Python shell
Question: Which index position is returned when the string method .find('python') is applied to the string 'learning python programming'? 8 9 1 2
Answer: 9
Question: Complete the function add_item(numeric_list, new_number) that takes a list of numbers and a new number, and returns a new list that appends the new number to the end of the list. For example, add_item([1, 2, 3], 4) should return [1, 2, 3, 4].
Answer: def add_item(numeric_list, new_number): numeric_list.append(new_number) return numeric_list
Question: Complete the function update_grade(grades, student, new_grade) that takes a grades dictionary, a student name, and a new grade, then updates that student's grade and returns the dictionary.
Answer: def update_grade(grades, student, new_grade): grades[student] = new_grade return grades
Question: Which for loop correctly iterates through a list of student names?
Answer: for name in ['Alice', 'Bob', 'Carol']:
Question: A program needs to display only positive, non-zero numbers from a list containing a mixture of integer and decimal values.
Answer: if number > 0:
Question: Fix the logic error in this function that should return the larger of two numbers.
Answer: def find_maximum(a, b): if a < b: return b
Question: def find_maximum(a, b): if a < b: return a else: return b
Answer: else: return a Tip: Correctly returning the larger of two numbers using if-else You can use either approach: 1nn Using a < b: if a < b: return b else: return a 2nn Using a > b: if a > b: return a else: return b n Key point: The if condition and the corresponding return statements must align so the larger number is returned. Swapping the comparison requires swapping the return values accordingly.