Geschreven door studenten die geslaagd zijn Direct beschikbaar na je betaling Online lezen of als PDF Verkeerd document? Gratis ruilen 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

Study Guides Questions and Answers

Beoordeling
-
Verkocht
-
Pagina's
4
Cijfer
A+
Geüpload op
05-01-2025
Geschreven 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

Meer zien Lees minder
Instelling
PTS
Vak
PTS

Voorbeeld van de inhoud

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

Geschreven voor

Instelling
PTS
Vak
PTS

Documentinformatie

Geüpload op
5 januari 2025
Aantal pagina's
4
Geschreven in
2024/2025
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

$13.49
Krijg toegang tot het volledige document:

Verkeerd document? Gratis ruilen Binnen 14 dagen na aankoop en voor het downloaden kun je een ander document kiezen. Je kunt het bedrag gewoon opnieuw besteden.
Geschreven door studenten die geslaagd zijn
Direct beschikbaar na je betaling
Online lezen of als PDF


Ook beschikbaar in voordeelbundel

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
Pogba119 Harvard University
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
57
Lid sinds
1 jaar
Aantal volgers
2
Documenten
5240
Laatst verkocht
12 uur geleden
NURSING TEST

BEST EDUCATIONAL RESOURCES FOR STUDENTS

3.8

13 beoordelingen

5
5
4
3
3
4
2
0
1
1

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Bezig met je bronvermelding?

Maak nauwkeurige citaten in APA, MLA en Harvard met onze gratis bronnengenerator.

Bezig met je bronvermelding?

Veelgestelde vragen