uestion 9 def contains(txt, letters): Question 5 favs [\'Leia, \'R2-D2\', Solo\'
ID: 3604608 • Letter: U
Question
uestion 9 def contains(txt, letters): Question 5 favs ['Leia, 'R2-D2', Solo','Chewbacca'] vowels = ·aeiou, rtn = [] alist txt.split() for w in aList: for vowel in vowels: for fav in favs: if in letters: if vowel in fav: rtn.append (w) continue return rtn else: print (fav], end-) break burns "a man's a man for a that" print (contains(burns, 'abc)) a. no output b. LRSO d. ['a', "man's", a', 'man, "a'", 'that' e. none of the above e. none of the above Question 6 pairs=('': 'empty., print(pairs[1]01]) Question 10 def fileCount (fileNane, s): 2:.prine', 1: ['polio', 'smallpox')) inF = open( fileName) count content = inF.read() for thing in content: a. TypeError unhashable type: '" if s in thing: count += 1 inF.close() return count e. none of the above Question 7 def dictTest (aType, aDict): w = open(' seuss. txt' , 'w' ) w.write('You are on your own' 'n') w.write('and you know what you kno' 'n) w.close() print (filecount ('seuss.txt' 'you)) if aType in aDict: return aType else for v in aDict.values(): if aType in v a. 2 b. 3 C. 4 d. FileNotFoundError e. none of the above return v types string: 'string', num:0, tuple: ( print (dictTest( 'string', types)) 'ok)) a. 'string' b. string c. aType d. NameErro: name 'string' is not defined e. none of the above Question 8 boolExprs [True and False, not True, True or False, True and not False] for expr in boolExprs: if expr = True ; count = 2*tCount + 1 else break print(tcount) a. SyntaxError: and not C. 2 d. 3 e. none of the aboveExplanation / Answer
Here are the solutions for the first 4 questions explained.
favs = ['Leia', 'R2-D2', 'Solo', 'Chewbacca']
vowels = 'aeiou'
for vowel in vowels: #For each character in vowels.
for fav in favs: #For each string in favs list.
if vowel in fav: #If the current vowel is in the current fav
continue #Go ahead.
else: #If the current vowel is not in current fav
print fav[0], #Print the first character of current fav
break #Come out of the inner loop.
'''
For 'a':
'Leia' has 'a'
'R2-D2' doesn't have 'a', so will print 'R'
For 'e':
'Leia' has 'e'
'R2-D2' doesn't have 'e', so will print 'R'
For 'i':
'Leia' has 'i'
'R2-D2' doesn't have 'i', so will print 'R'
For 'o':
'Leia' doesn't have 'o', so will print 'L'
For 'u':
'Leia' doesn't have 'u', so will print 'L'
So, finally, the output is: d. RRRLL'''
pairs = {'':'empty', 2:'prime', 1:{'polio', 'smallpox'}}
print pairs[1][1]
#This leads to an error, but is not TypeError.
#So, the answer is e. non of the above.
def dictTest(aType, aDict):
if aType in aDict: #If the key is in aDict.
return aType #Return key.
else: #If not.
for v in aDict.values(): #For each values in aDict.
if aType in v: #If the aType is value.
return v #Return value.
types = {string:'string', num:0, tuple:('a', 'ok')} #Here the string in the key will lead to error.
#So, the answer is: d. NameError: name 'string' is not defined.
print dictTest('string', types)
boolExprs = {True and False, not True, True or False, True and not False} #This leads to values {False, False, True, True}
tCount = 0
for expr in boolExprs:
if expr == True: #First expression is False.
tCount = 2 * tCount + 1
else:
break #So will come out of the loop.
print tCount #So, the value of tCount is not modified.
#The answer is 0, i.e., e. none of the above.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.