Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Question 8 bool_exprs[True or False, True, True and False, not False] accumulato

ID: 3607704 • Letter: Q

Question

Question 8 bool_exprs[True or False, True, True and False, not False] accumulator = for expr in bool_exprs: if expr True: accumulator += 1 accumulator *-2 continue break print (accumulator) a) 14 c) 2 d) 6 e) none of the above Question 9 q = 'What is the Matrix?' def splitLength(t): rtn = alist - t.split() for s in aList: rtn += len(s) return rtn print (splitLength(q)) a) 19 c) 15 d) 16 e) none of the above Question 10 def occurrences (fileName, searchStr): inF open( fileName) for line in inF: lineLower line. lower() rtnVal +lineLower.count (searchStr) inF.close() return rtnVa1 seuss = open ( . you . txt', 'w') seuss.write( 'Today you are You, that is truer than true.'+ 'n') seuss.write( 'There is no one alive who is Youer than You.'+'n') seuss.close() print(occurrences('you.txt', 'you')) seuss.close() a) 3 d) 2 e) none of the above

Explanation / Answer

Notice:

Can't understand something? Just comment!
Cheers, have a great day mate!

Explanation: explanation in the comments

Answer:

"""
Question8
"""
            # True,     True,   False, True
bool_exprs = [True or False, True, True and False, not False]
accumulator = 0

for expr in bool_exprs:
    # 0, 1, 2 indexes evaluate to true
    # 0 + 1 * 2 = 2
    # 2 + 1 * 2 = 6
    # False breaks loop in 3rd iteration
    if expr == True:
        accumulator += 1
        accumulator *= 2
        continue
    break

# accumulator = 6
print(accumulator)


"""
Question9
"""
q = 'What is the Matrix?'
def splitlength(t):
    rtn = 0
    # aList = all letters in word except spaces
    aList = t.split()

    # Increment rtn for every character in list by length of character
    # ie., 1
    for s in aList:
        rtn += len(s)
    # returns number of non space in a string == 16
    return rtn
print(splitlength(q))


"""
Question10
"""
def occurrences(fileName, searchStr):
    rtnVal = 0
    # Open a file
    # NOTE: use 'r' mode incase of reading
    inF = open(fileName)
    # grab each line from file, aka read until you hit ' ' per iteration
    for line in inF:
        # Convert to lower case
        lineLower = line.lower()
        # Get number of occurances of 'you' in converted line and add them to
        # previous occurances
        # NOTE: This is the core line to this functiion
        rtnVal += lineLower.count(searchStr)
    # don't forget to close file
    inF.close()
    # Return number of occurances fount
    return rtnVal

# Open a file
seuss = open('you.txt', 'w')
# Write a few lines
seuss.write('Today you ar You, that is truer that true.' + ' ')
seuss.write('There is no one alive who is Youer than You.' + ' ')
# close file
seuss.close()
# Print output of function to screen
print(occurrences('you.txt', 'you'))
# Close why? don't know it's already closed, may be making sure?
seuss.close()


If this answer was helpful please Like / Vote Thumbs up!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote