CMSC 201 Fall 2024 Practice Final Exam
23 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

How many times will the loop run in the following code? for x in range(3, 17, 2): print(x)

  • 14
  • 3
  • 7 (correct)
  • 5

The line 'if my_list:' in the function 'find_depth' checks if the list is empty.

True (A)

What does the recursive call in the function 'find_depth' do?

It calls itself with a sublist to calculate the depth.

In the expression not(my_int % 2), 'not' checks if the result is _____ .

<p>zero</p> Signup and view all the answers

Match the following programming concepts with their definitions:

<p>Loop = A block of code that repeats a certain number of times Recursive call = A function that calls itself Data structure = A way of organizing and storing data Algorithm = A step-by-step procedure for solving a problem</p> Signup and view all the answers

Which line in the function 'find_depth' contains the recursive call?

<p>Line 5 (B)</p> Signup and view all the answers

The expression not(my_int % 2) will return true when my_int is odd.

<p>False (B)</p> Signup and view all the answers

What is the primary purpose of using a loop in programming?

<p>To execute a block of code repeatedly as long as a condition is true.</p> Signup and view all the answers

What will the output of the following code be? print( composers.get("Scriabin", "Who?!") )

<p>Who?! (B)</p> Signup and view all the answers

The statement composers['Scarlatti'] = 17 will raise an error if 'Scarlatti' is not already a key in the dictionary.

<p>False (B)</p> Signup and view all the answers

What is the output of print(composers["Chopin"], composers["Beethoven"], composers["Vivaldi"]) if composers is defined as given?

<p>24 9 4</p> Signup and view all the answers

The number 64 in binary is represented as __________.

<p>1000000</p> Signup and view all the answers

Match the decimal numbers with their corresponding binary conversions:

<p>64 = 1010000 183 = 00010111</p> Signup and view all the answers

Which statement correctly evaluates if a list named scotsmen is non-empty and a variable ship_of_theseus has at least 12 elements?

<p>len(scotsmen) &gt; 0 and len(ship_of_theseus) &gt;= 12 (D)</p> Signup and view all the answers

The binary number 1101 1011 is equivalent to the decimal number 219.

<p>True (A)</p> Signup and view all the answers

Convert the decimal number 183 to hexadecimal.

<p>B7</p> Signup and view all the answers

The code snippet print("\\\nMerry\nChristmas!\") will output "Merry Christmas!".

<p>False (B)</p> Signup and view all the answers

What does the code print(the_list) output after executing list_add(the_list) twice, given the_list = ['1', '7']?

<p>['1', '7', '3', '3']</p> Signup and view all the answers

In the code a_list = ['Python', 'is', 'a', 'fun', 'time'], the expression a_list[4:10] outputs ___________.

<p>[]</p> Signup and view all the answers

Match the following functions with their expected output:

<p>print(a_list[2:4]) = ['a', 'fun'] print(a_list[4:10]) = [] print(a_list[:3]) = ['Python', 'is', 'a'] hello(15) = prints 'hello' multiple times</p> Signup and view all the answers

What is the result of three_plus_one(1)?

<p>4</p> Signup and view all the answers

The function rec_fun(5) produces an output containing only the letter 'a'.

<p>False (B)</p> Signup and view all the answers

When the following matrix code is run, what is printed? the_matrix = [[4, 2, 7], [8, 5, 6], [9, 1, 3]]; print(the_matrix)

<p>[[4, 2, 7], [8, 5, 6], [9, 1, 3]] (A)</p> Signup and view all the answers

Flashcards

Loop iterations for range(3, 17, 2)

The range(3, 17, 2) function generates numbers starting at 3, incrementing by 2, up to (but not including) 17. This results in a sequence of numbers: 3, 5, 7, 9, 11, 13, 15. Therefore the loop will execute 7 times.

Recursive call line in find_depth function

The line of code d = 1 + find_depth(sublist) within the find_depth function constitutes a recursive function call; this function calls itself with a smaller input to complete the task based on the defined conditions.

When not(my_int % 2) is True

The expression not(my_int % 2) evaluates to True when my_int is an even number. The modulo operator (%) returns the remainder of a division—if the remainder is 0, it's even (divisible by 2).

Academic dishonesty

Includes cheating, fabrication, plagiarism, and helping others commit these acts.

Signup and view all the flashcards

Boolean Expression: Non-empty list and list length

A Boolean expression that returns True only if a list named 'scotsmen' is not empty AND another list named 'ship_of_theseus' has at least 12 elements.

Signup and view all the flashcards

Boolean Expression: String comparison and list size

A Boolean expression that returns True if and only if the string 'game' is equal to either 'chess' or 'checkers' (case insensitive), and the 2D list 'board_size' has a size of 8x8.

Signup and view all the flashcards

Dictionary: Accessing non-existent key

Attempting to access a key that does not exist within a dictionary using square brackets will result in a KeyError.

Signup and view all the flashcards

Dictionary: Using the 'get' method

The 'get' method provides a safe way to access a dictionary key. If the key does not exist, it returns a default value instead of raising a KeyError.

Signup and view all the flashcards

Dictionary: Modifying Value

You can modify the value associated with existing keys in a dictionary by assigning a new value using square brackets.

Signup and view all the flashcards

Decimal to Binary Conversion

Converting a decimal number to binary involves repeatedly dividing by 2 and recording the remainders.

Signup and view all the flashcards

Decimal to Hexadecimal Conversion

To convert a decimal number to hexadecimal, repeatedly divide by 16 and record the remainders.

Signup and view all the flashcards

Binary to Decimal Conversion

Converting a binary number to decimal involves summing the values of each digit multiplied by its corresponding power of 2.

Signup and view all the flashcards

Hexadecimal to Binary Conversion

Converting a hexadecimal number to binary involves converting each hexadecimal digit to its 4-bit binary equivalent.

Signup and view all the flashcards

Binary Representation of FD30A15E

The hexadecimal number FD30A15E translates to the binary number 11111101 00110000 10100001 01011110.

Signup and view all the flashcards

String Escape Sequences

Escape sequences in strings are special character combinations that represent specific characters, like \n for newline or \ for a backslash.

Signup and view all the flashcards

Output of 'print(\\nMerry\nChristmas!\)'

The code prints 'Merry' on a new line, followed by 'Christmas!' on a new line, and then ends with a single backslash.

Signup and view all the flashcards

Modifying a List Inside a Function

Passing a list to a function allows the function to modify the original list by appending elements or changing existing values.

Signup and view all the flashcards

List Slicing Syntax

List slicing uses the format 'my_list[start:stop:step]' to extract a subset of a list. It provides a flexible way to access parts of the list.

Signup and view all the flashcards

Recursive Function with Base Case

A recursive function calls itself within its definition, but includes a base case where it stops calling itself to prevent infinite recursion.

Signup and view all the flashcards

Function with Nested If Statements and Recursion

The function hello uses nested if statements with recursion to print 'hello' repeatedly. The recursion stops when the count becomes negative.

Signup and view all the flashcards

Study Notes

Exam Information

  • Course: CMSC 201
  • Semester: Fall 2024
  • Exam Type: Practice Final Exam
  • Total Points: 165 points (5 extra points)
  • Discussion Sections: Students are assigned to a discussion section (numbers listed)

Exam Instructions

  • Name: Write your name neatly on the exam.
  • Login ID: Use your UMBC email ID without the "@umbc.edu" portion.
  • Pencil: The exam must be completed using a pencil.
  • Name on Every Page: Write your name at the top of every page.

Undergraduate Honors Statement

  • Academic Honesty: Students agree to uphold the highest standards of academic honesty in the course.
  • Academic Dishonesty: Cheating, fabrication, plagiarism, and assisting others in committing academic dishonesty is prohibited.
  • Academic Integrity: Students agree to abide by the University's and course's academic integrity policies.

Multiple Choice

  • Format: Multiple choice questions with bubbles for the correct answer.
  • Points: 3 points per question
  • Total Points: 30 points (3 points each)
  • Instructions: Clearly and cleanly fill in the bubbles for the selected option.

Additional Questions

  • Recursive Call: A recursive call in a function is specified.
  • Mutable vs Immutable Types: Lists are mutable data types that are passed by reference.
  • Error: A type error is described, and its cause is explained.
  • Boolean Expressions: Boolean expressions evaluate to True or False. Students must write correct boolean expressions.
  • Dictionary Evaluation: Students are required to provide the results of dictionary operations, recognizing any errors.

Binary, Hexadecimal & Decimal

  • Conversions: Convert numbers between binary, hexadecimal, and decimal formats.
  • Decimal to Binary/Hexadecimal: Work for conversions of integers
  • Binary/Hex to Decimal: Work for conversions of given values

Code Evaluation

  • Programming Concepts: Evaluates code snippets and their outputs.
  • Formatted Output: Output formatting is a consideration in evaluating code.

Debugging

  • Errors: Find and correct five errors in given code snippets.
  • Recursive function: Creating function for binary number operations and vowel counting.
  • Debugging (Part 2): Find, and fix errors for a second set of code.

Programming Problems

  • 2D Lists: Finding minimum of maximum in 2-dimensional lists

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Description

Prepare for your CMSC 201 final exam with this practice test designed for Fall 2024. The exam evaluates your understanding of course material through multiple-choice questions. Ensure you follow the exam instructions carefully for successful completion.

More Like This

Use Quizgecko on...
Browser
Browser