100% satisfaction guarantee Immediately available after payment Both online and in PDF No strings attached
logo-home
CSC148 Exam with Complete solutions (A Graded) $13.24   Add to cart

Exam (elaborations)

CSC148 Exam with Complete solutions (A Graded)

 0 view  0 purchase
  • Course
  • CSC148
  • Institution
  • CSC148

CSC148 Exam with Complete solutions (A Graded)

Preview 3 out of 23  pages

  • September 7, 2024
  • 23
  • 2024/2025
  • Exam (elaborations)
  • Questions & answers
  • CSC148
  • CSC148
avatar-seller
KenAli
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

The benefits of buying summaries with Stuvia:

Guaranteed quality through customer reviews

Guaranteed quality through customer reviews

Stuvia customers have reviewed more than 700,000 summaries. This how you know that you are buying the best documents.

Quick and easy check-out

Quick and easy check-out

You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.

Focus on what matters

Focus on what matters

Your fellow students write the study notes themselves, which is why the documents are always reliable and up-to-date. This ensures you quickly get to the core!

Frequently asked questions

What do I get when I buy this document?

You get a PDF, available immediately after your purchase. The purchased document is accessible anytime, anywhere and indefinitely through your profile.

Satisfaction guarantee: how does it work?

Our satisfaction guarantee ensures that you always find a study document that suits you well. You fill out a form, and our customer service team takes care of the rest.

Who am I buying these notes from?

Stuvia is a marketplace, so you are not buying this document from us, but from seller KenAli. Stuvia facilitates payment to the seller.

Will I be stuck with a subscription?

No, you only buy these notes for $13.24. You're not tied to anything after your purchase.

Can Stuvia be trusted?

4.6 stars on Google & Trustpilot (+1000 reviews)

79064 documents were sold in the last 30 days

Founded in 2010, the go-to place to buy study notes for 14 years now

Start selling
$13.24
  • (0)
  Add to cart