Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Exam (elaborations)

CIS 4930 Python Midterm Exam Questions with Correct Answers Latest Update

Rating
-
Sold
-
Pages
8
Grade
A+
Uploaded on
04-10-2025
Written in
2025/2026

CIS 4930 Python Midterm Exam Questions with Correct Answers Latest Update What are the three characteristics of every object? - Answers Every object has 1) an identity 2) a type (its class) 3) a value What is an object's identity? - Answers A number representing the object's physical location in memory What is an object's type? - Answers It's internal data representation and the methods it supports What happens during a context manager's scope? - Answers If there are no exceptions being handled, the exit function will receive None as the value of all three of its arguments. If there are exceptions, the exit function should define what steps, if any, to take, including automatic resource management (cleanup). At the end of exit, return either - True: any pending exception is cleared and the program continues execution normally with the first statement after the with block - False: preferrable; if an exception happened, it was not completely handled and should be propagated up towards the interpreters at runtime What three protocols should you adhere to rigorously? - Answers 1) Create a proper object representation using the __repr__() method 2) Iteration is a very big deal; make sure your code works with Python's for statement. 3) Use context managers and the with statement for resource management. How do you define a function? - Answers - Use the def statement; i.e. def function_name() How do you check for default variable values and None? - Answers - Default parameters are evaluated once when the function is first defined, not each time the function is called. - Use None as the default value for all arguments that should be mutable. - As a rule, only use immutable objects for default argument values. When can you mix positional and keyword arguments in a function call? - Answers 1) Positional arguments appear first in the call. 2) Values are provided for all non-optional arguments. 3) No argument receives more than one value. How do you define a function that accepts all arguments? - Answers def func(*args, **kwargs) Can you redefine Python precedence evaluation? - Answers No Write a function to perform math on an arbitrary number of arguments, including proper type hinting and documentation. - Answers def addMany(first: int, *args) - int: if not isinstance(int, first): raise TypeError("First value must be an integer") total: int = first for arg in args: if isinstance(int, arg): total += arg return total Write code to manipulate a data structure and provide output as requested. - Answers portfolio = [] d(("GOOG", 100, 490.10)) d(("IBM", 50, 91.10)) total = sum([shares * price for _, shares, price in portfolio]) Match the following use cases to their Python control structure/keyword(s) 1) Loop infinitely until some condition is ment 2) Iterate over all elements of a sequence 3) Automatically release a resource when it goes out of scope 4) Conditionally execute one of several code blocks 5) Attempt to do something and handle any unusual conditions - Answers 1) while 2) for 3) with 4) if-elif-else 5) try-except Match the following code snippets to the type of literal that they define 1) x = (1, 2, 3) 2) x = [1, 2, 3] 3) x = {1, 2, 3} 4) x = {'a': 1, 'b': 2, 'c': 3} 5) x = "hello world" - Answers 1) tuple 2) list 3) set

Show more Read less
Institution
CIS 4930
Course
CIS 4930

Content preview

CIS 4930 Python Midterm Exam Questions with Correct Answers Latest Update 2025-2026

What are the three characteristics of every object? - Answers Every object has

1) an identity

2) a type (its class)

3) a value

What is an object's identity? - Answers A number representing the object's physical location in
memory

What is an object's type? - Answers It's internal data representation and the methods it supports

What happens during a context manager's scope? - Answers If there are no exceptions being
handled, the exit function will receive None as the value of all three of its arguments.

If there are exceptions, the exit function should define what steps, if any, to take, including
automatic resource management (cleanup).

At the end of exit, return either

- True: any pending exception is cleared and the program continues execution normally with the
first statement after the with block

- False: preferrable; if an exception happened, it was not completely handled and should be
propagated up towards the interpreters at runtime

What three protocols should you adhere to rigorously? - Answers 1) Create a proper object
representation using the __repr__() method

2) Iteration is a very big deal; make sure your code works with Python's for statement.

3) Use context managers and the with statement for resource management.

How do you define a function? - Answers - Use the def statement; i.e. def function_name()

How do you check for default variable values and None? - Answers - Default parameters are
evaluated once when the function is first defined, not each time the function is called.

- Use None as the default value for all arguments that should be mutable.

- As a rule, only use immutable objects for default argument values.

When can you mix positional and keyword arguments in a function call? - Answers 1) Positional
arguments appear first in the call.

2) Values are provided for all non-optional arguments.

, 3) No argument receives more than one value.

How do you define a function that accepts all arguments? - Answers def func(*args, **kwargs)

Can you redefine Python precedence evaluation? - Answers No

Write a function to perform math on an arbitrary number of arguments, including proper type
hinting and documentation. - Answers def addMany(first: int, *args) -> int:

if not isinstance(int, first):

raise TypeError("First value must be an integer")

total: int = first

for arg in args:

if isinstance(int, arg):

total += arg

return total

Write code to manipulate a data structure and provide output as requested. - Answers portfolio
= []

portfolio.append(("GOOG", 100, 490.10))

portfolio.append(("IBM", 50, 91.10))

total = sum([shares * price for _, shares, price in portfolio])

Match the following use cases to their Python control structure/keyword(s)

1) Loop infinitely until some condition is ment

2) Iterate over all elements of a sequence

3) Automatically release a resource when it goes out of scope

4) Conditionally execute one of several code blocks

5) Attempt to do something and handle any unusual conditions - Answers 1) while

2) for

3) with

4) if-elif-else

Written for

Institution
CIS 4930
Course
CIS 4930

Document information

Uploaded on
October 4, 2025
Number of pages
8
Written in
2025/2026
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

10.99 $
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF


Also available in package deal

Get to know the seller

Seller avatar
Reputation scores are based on the amount of documents a seller has sold for a fee and the reviews they have received for those documents. There are three levels: Bronze, Silver and Gold. The better the reputation, the more your can rely on the quality of the sellers work.
TutorJosh Chamberlain College Of Nursing
Follow You need to be logged in order to follow users or courses
Sold
434
Member since
1 year
Number of followers
17
Documents
31669
Last sold
2 days ago
Tutor Joshua

Here You will find all Documents and Package Deals Offered By Tutor Joshua.

3.5

73 reviews

5
26
4
16
3
14
2
1
1
16

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions