100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached 4.2 TrustPilot
logo-home
Exam (elaborations)

CSC148 Exam with Complete solutions (A Graded)

Rating
-
Sold
-
Pages
23
Grade
A+
Uploaded on
07-09-2024
Written in
2024/2025

CSC148 Exam with Complete solutions (A Graded)

Institution
CSC148
Course
CSC148










Whoops! We can’t load your doc right now. Try again or contact support.

Written for

Institution
CSC148
Course
CSC148

Document information

Uploaded on
September 7, 2024
Number of pages
23
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

Content preview

CSC148 Exam with Complete solutions (A Graded)
What happens between when the function is executing and when it is finished - ANSWER There
will be a call stack when it is executing. Once it finishes, the call stack is deleted, including the
local variables. The function will finish executing either when it reaches the end of the function
or if it reaches a return statement.


def mess_about(n: int, s: str) -> None:
message = s * n
print(message)


if __name__ == '__main__':
count = 13
word = 'nonsense'
mess_about(count, word)

print(n) - ANSWER name error:n is not defined because there is no return statement in
the function


passing a reference to an immutable object

,like
def emphasize(s: str) -> None:
s = s + s + '!'


if __name__ == '__main__':
word = 'moo'
emphasize(word)

print(word) - ANSWER it will have no effect outside of the funciton because you can't
change an immutable, it will just create a new object


What is special about None - ANSWER we refer to it as both a value and its type.


difference between list and List - ANSWER List is if all are one type list is not as specific



explain class -> instance -> attribute - ANSWER A class is a block of code that defines a type of
data. The built-in Python types that you're familiar with like int, str, and list are all defined by
classes. Suppose we have a class called X. An object whose type is X is called an instance of
class X; for example, the object 3 is an instance of class int.



An instance of a class does not have to contain just a single piece of data as an int does; it can
hold a collection of data bundled together. Each individual piece of data in an instance is
called an instance attribute of the object.



what actually happens when you create a class? like in the tweet example in the readings 2.1 -
ANSWER 1. Create a new Tweet object behind the scenes.

2. Call __init__ with the new object passed to the parameter self, along with the other
three arguments (for who, when, and what).

3. Return the new object. This step is where the object is returned, not directly from the call
to __init__ in Step 2.

, Once we define the Tweet class, how many Tweet objects can we construct? - ANSWER There is
no limit.



tweet.like(10) what does the dot do in this case? - ANSWER we pass one argument, yet the
method has two parameters, self and n. What dot notation does for a method call is
automatically pass the value to the left of the dot (in this case, tweet) as the method's first
parameter self.



difference between class and method - ANSWER Methods are part of the very definition of the
class, and form the basis of how others can use the class. They are bundled together with the
class, and are automatically available to every instance of the class. In contrast, functions that
operate on a class instance must be imported separately before they are used. So it sounds like
functions are "less useful" than methods because you need to do a bit of extra work to use
them.



how do you express that it can be one of two different types when writing a function or
method? - ANSWER Union[int, float] shows that the type of the value can be an int or a float



value could be a certain type, or None, how do we express that - ANSWER Optional[int] which
is equivalent Union[int, None]



Callable[[int, str], bool] what does this mean - ANSWER a type expression for a function
that takes two arguments, an integer and a string, and returns a boolean


write the code that is needed to test the doc strings - ANSWER if __name__ == '__main__':
import doctest # import the doctest library
doctest.testmod()



what is an abstract data type - ANSWER An abstract data type (or ADT) defines some kind of
data and the operations that can be performed on it. It is a pure interface. It is looking primarily
at what data is stored and what can we do with that data

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.
KenAli West Virginia University
View profile
Follow You need to be logged in order to follow users or courses
Sold
84
Member since
1 year
Number of followers
5
Documents
17177
Last sold
1 week ago

2.9

19 reviews

5
4
4
4
3
4
2
0
1
7

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 exams and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can immediately select a different document that better matches what you need.

Pay how you prefer, start learning right away

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

Student with book image

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

Alisha Student

Frequently asked questions