ENGR 102 Exam
Tested Questions With Revised
Correct Detailed Answers
>Latest Update>>
1. Write the simplest expression that captures the desired comparison.
x is a key in the dict my_dict. - ANSWER x in my_dict
2. Write the simplest expression that captures the desired co...
1. Write the simplest expression that captures the desired comparison.
x is a key in the dict my_dict.
- ANSWER x in my_dict
2. Write the simplest expression that captures the desired comparison.
The character 'G' exists in the string my_str.
- ANSWER 'G' in my_str
3. How do you sort my_list from highest to lowest and then print the reversed
list? for i in reversed(sorted(my_list)):
- ANSWER print(i)
4. What does any(my_list) provide?
- ANSWER If the list contains non-zero elements, any() returns True, else
returns False
5. What does all(my_list) provide?
- ANSWER If the list contains a 0 element, all() returns False because not all
elements are non-zero, else returns True
Assume that my_list is [0, 5, 10, 15].
6. What is returned by any(my_list)? What is returned by all(my_list)?
- ANSWER True, False
,for (index, value) in enumerate(my_list):
print(index, value)
7. First prints the help because we ask for it in the code
then prints the rest of the function bc we call it
def myfunction(a, b=2, c):
return a * b * c
print(myfunction(1, 2, 3)) - ANSWER will print ERRRRROOOORR
to fix it:
def myfunction(a, b=2, c=2):
return a * b * c
print(myfunction(1, 2, 3))
#everything after the first thing you change has to change in the parameters
#maria's clear explanation: "a non default parameter can't follow a default
parameter
#be better Estelle
9. def add1(x):
if x + 1 < 10:
return x + 1
else:
return 'Too big!'
,print(add1(1), add1(24)) - ANSWER 2 Too big!
10. Don't forget: the coma automatically creates a space
x=4
y = timestwo(x)
def timestwo(x):
return x * 2
print(y) - ANSWER ERRRROOOOOR
the y that calls the function is before the function and python is stupid (unlike
java) so it doesn't get it
so u put it after :)
11. also: x in the function is not the same as the x = 4
mydict = {}
mylist = [1, 2, 3, 4, 5]
mydict['Length'] = len(mylist)
mydict['Max'] = max(mylist)
mydict['Min'] = min(mylist)
mydict['Crazy'] = mylist[1] * mylist[3] - mylist[-1]
for i in mydict:
listname.remove(5) - ANSWER pops the last index if you don't specify an
index
The benefits of buying summaries with Stuvia:
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
You can quickly pay through credit card or Stuvia-credit for the summaries. There is no membership needed.
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 NURSINGDICTIONARY. Stuvia facilitates payment to the seller.
Will I be stuck with a subscription?
No, you only buy these notes for $12.99. You're not tied to anything after your purchase.