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)

Study Guides Questions and Answers

Rating
-
Sold
-
Pages
4
Grade
A+
Uploaded on
05-01-2025
Written in
2024/2025

Study Guides Questions and Answers What is one similarity between print () and input()? Print & input similarity + 4 pts Both generate a string output + 4 pts Both built-in or standard library functions + 4 pts Correct, other than above + 1 pts Attempted but mostly incorrect or too vague + 0 pts Completely wrong or Blank - 2 pts Too Vague - 1 pts Mistake - 0.5 pts Minor mistake Whenever the Python interpreter needs to evaluate a name(of a variable, function, etc...), it searched for the name definition in this order: 1: __________ 2: __________ 3: __________ Three from the following 4: + 1.5 pts Local + 1.5 pts Global + 1.5 pts Module Import + 1.5 pts Built-in Order of Answers: + 1.5 pts Correct Order + 1 pts Partial Correct Order Explain the differences between 'import math' and 'from math import sqrt' or 'from math import*' import math vs from math import */sqrt + 5 pts "Import math" and "From math import " import all the functions/objects of the module while "from module import sqrt" imports the specific function/object. "From math import " and "From math import sqrt" allow the object to be referred to without including the module from which it was imported, which might lead to pollution of the namespace. + 4 pts Partially Correct. Did not correctly explain the meaning of from math import sqrt or * What is the main difference between print () and return? Given an example. Print vs Return + 2 pts Explain print + 2 pts Explain return + 2 pts Print example + 2 pts return example + 0 pts Blank In the expression: count %= count - offset + 2 which operator has the lowest precedence? Why? +4 pts Correct operator (%=) +4 pts Correct explanation: Since the modulo operator is chained with the assignment operator(which has lowest precedence), the %= will execute last. +0 pts Completely wrong Do the keys of a dictionary best model a list or a set? Dictionary keys: list vs sets + 5 pts [List or Set] Set + 5 pts [Uniqueness] Keys must be unique + 5 pts [Order] Keys and sets are unordered. + 5 pts [Mutability] Keys are immutable, and elements of a set have to be immutable + 2 pts General neutral / correct statements - 2 pts General incorrect statements + 1 pts Not blank. Give two examples of functionality/applications that you can do with a dictionary you can't do with a list. Two examples where you can use dictionaries but not lists + 5 pts Correct + 2.5 pts Relationships between keys and values + 2.5 pts Addressing values by key rather than index + 1 pts Partially Correct / Not Blank + 2.5 pts Keys are unique + 2.5 pts Dictionaries are unordered Given a value for a dictionary, is there a built-in way to lookup the corresponding key? Explain your answer. Lookup key by value in dictionary + 4 pts There is NOT a built-in way. + 4 pts Keys are unique while values are not. + 4 pts Many keys might have the same associated value. + 2 pts Keys are immutable while values are not. + 2 pts You can only use a key to lookup a value with built-ins. + 1 pts General correct comments about dictionaries not mentioned on other rubric points above. Why does Python provide so many different ways to structure & store data? What would happen if Python didn't provide data structures? Reasons for Structured Types +0 pts Completely wrong +4 pts Answered first question: many ways to associate/store data +4 pts Programs would have an unmanageable number of variables For the code below, draw a visual representation of the list, cs_courses: Course = namedtuple('Course', 'dept nurn title instr units') ics31 = Course ( 'ICS', '31','Intro to Programming', 'Alfaro', 4. 0) ics32 = Course ( 'ICS', '32','Programming with Libraries', 'Hermans', 4.0) cs_courses = [ics31, ics32] Visualization + 8 pts Correct + 1 pts cs_courses: index(0-1) & neg index(-1~-2) + 1 pts cs_courses: Structure: 2 Squares for each namedtuple + 2 pts For each cs_courses[x]: namedtuple: field names + 2 pts For each cs_courses[x]: namedtuple: field names: index(0-4) + 2 pts For cs_courses[1]: namedtuple: values for each field Give two examples of functionality/applications that you can do with a dictionary you can't do with a list. Two examples you can use dictionaries but not lists + 5 pts Correct + 2.5 pts Relationships between keys and values + 2.5 pts Addressing values by key rather than index + 2.5 pts Keys are unique + 2.5 pts Dictionaries are unordered + 1 pts Partially Correct / Not Blank When can you change the field of a namedtuple and not change the original object's id? Write a program to demonstrate. + 4 pts Answer: when the field being changed is a mutable object + 4 pts Example: nt = namedtuple('nt','immutable mutable') e = nt('s',[0]) d(1) Why is it good advice to use parentheses with Boolean expressions? Give an example where it is necessary. Boolean Expressions + 4 pts override operator precedence + 4 pts For readability of a very long and unreadable boolean expression + 4 pts Example with both "and" and "or" operators where parentheses are used to increase the precedence of the "or" operator + 2.5 pts Provided an example but not very compelling + 1 pts Not blank, but incorrect statements Why are the relational operators called "relational"? Relational Operators + 8 pts Compare two values to determine how they relate to one another (, , =, =, ==, !=) + 8 pts Makes a binary statement ranking two values + 4 pts Partially correct based on above criteria + 1 pts Not blank, but incorrect statements Explain the differences between positive and negative indexing in Python. Positive vs Negative Indexing + 0 pts Blank + 5 pts Correct + 2.5 pts Start Index: positive uses '0', negative is -1 + 2.5 pts Incrementing: positive use +1, negative uses -1 + 2.5 pts Last Index: positive = len(lst)-1, negative = -len(lst) + 1 pts Partial Credit: not blank What is the main difference between looping-by-value and looping-by-index(as discussed during lecture)? Using code, give an example to describe your answer. Difference: Loop-By-Value 4 pts 2.1 Difference + 2 pts DIFFERENCE: Looping-by-Index allows direct access to containers original contents to be modified. + 1 pts Not the main difference but a valid difference + 0 pts Incorrect

Show more Read less
Institution
PTS
Course
PTS

Content preview

Study Guides Questions and Answers

What is one similarity between print () and input()? - answer Print & input similarity
+ 4 pts Both generate a string output
+ 4 pts Both built-in or standard library functions
+ 4 pts Correct, other than above
+ 1 pts Attempted but mostly incorrect or too vague
+ 0 pts Completely wrong or Blank
- 2 pts Too Vague
- 1 pts Mistake
- 0.5 pts Minor mistake

Whenever the Python interpreter needs to evaluate a name(of a variable, function,
etc...), it searched for the name definition in this order:
1: __________
2: __________
3: __________ - answer Three from the following 4:
+ 1.5 pts Local
+ 1.5 pts Global
+ 1.5 pts Module Import
+ 1.5 pts Built-in

Order of Answers:
+ 1.5 pts Correct Order
+ 1 pts Partial Correct Order

Explain the differences between 'import math' and 'from math import sqrt' or 'from math
import*' - answer import math vs from math import */sqrt
+ 5 pts "Import math" and "From math import *" import all the functions/objects of the
module while "from module import sqrt" imports the specific function/object. "From math
import *" and "From math import sqrt" allow the object to be referred to without including
the module from which it was imported, which might lead to pollution of the namespace.
+ 4 pts Partially Correct. Did not correctly explain the meaning of from math import sqrt
or *

What is the main difference between print () and return? Given an example. - answer
Print vs Return
+ 2 pts Explain print
+ 2 pts Explain return
+ 2 pts Print example
+ 2 pts return example
+ 0 pts Blank

Written for

Institution
PTS
Course
PTS

Document information

Uploaded on
January 5, 2025
Number of pages
4
Written in
2024/2025
Type
Exam (elaborations)
Contains
Questions & answers

Subjects

$13.49
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

Thumbnail
Package deal
PTS EXAM BUNDLE
-
56 2025
$ 30.99 More info

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.
Pogba119 Harvard University
View profile
Follow You need to be logged in order to follow users or courses
Sold
58
Member since
1 year
Number of followers
2
Documents
5334
Last sold
5 days ago
NURSING TEST

BEST EDUCATIONAL RESOURCES FOR STUDENTS

3.9

14 reviews

5
6
4
3
3
4
2
0
1
1

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