PE2: Python Essentials 2 – 4.7 Module 4 Test Exam Answers Full 100% 2023 2024

This is Cisco NetAcad SkillsForAll PE2: Python Essentials 2 – Module 4 Test Exam Answers Full 100% in 2023 and 2024. All answers have been verified by experts.

  1. Which of the following open modes allow you to perform read operations? (Select two answers)

    • r
    • a
    • r+
    • w
  2. What is the expected result of executing the code?

    def I():
           s = 'abcdef'
           for c in s[::2]:
                   yield c
    
    for x in I():
             print(x, end=' ')
    • It will print abcdef
    • It will print an empty line
    • It will print bdf
    • It will print ace
  3. What keyword would you us to define an anonymous function?

    • afun
    • lambda
    • def
    • yield
  4. Select the true statements. (Select two answers)

    • The lambda function can accept a maximum of two arguments
    • The lambda function can evaluate multiple expressions
    • The lambda function can evaluate only one expressrion
    • The lambda function can accept any number of arguments
  5. Look at the code below:

    my_list = [1, 2, 3]
    # insert line of code here.
    print(foo)

    Which snippet would you insert in order for the program to output the following  result (tuple):

    1, 4, 27

    • foo = list(map(lambda x: x**x, my_list))
    • foo = tuple(map(lambda x: x*x, my_list))
    • foo = list(map(lambda x: x*x, my_list))
    • foo = tuple(map(lambda x: x**x, my_list))
  6. What is the expected output of the following code?

    from datetime import date
    date_1 = date(1992, 1, 16)
    date_2 = date(1992, 2, 5)
    print(date_1 - date_2)
    • 345
    • 345 days
    • 345, 0:00:00
    • 345 days, 0:00:00
  7. Which program will produce the following output:

    Mo Tu We Th Fr Sa Su
    • import calendar
      print(calendar.weekheader(3))
    • import calendar
      print(calendar.weekheader(2))
    • import calendar
      print(calendar.week)
    • import calendar
      print(calendar.weekheader())
  8. What is the expected result of executed the following code?

    def o(p):
       def q():
          return'*' *p
       return q
    r = o(1)
    s = o(2)
    print(r9) + s())
    • it will print ***
    • it will print ***
    • it will print **
    • it will print *
  9. Look at the code below:

    my_tuple = (0, 1, 2. 3, 4, 5, 6)
    # Insert line of code here.
    print(foo)

    Which snippet would you insert in order for he program  to output the following result (list):

    [2, 3, 4, 5, 6]
    • foo = list(filter(lambda x: x-0 and x-1, my_tuple))
    • foo  - list(filter(lambda x: x==0 and x==1, my_tuple))
    • foo = tuple(filter(lambda x: x>1, my_tuple))
    • foo = tuple(filter(lambda x: x-0 and x-1, my_tuple))
  10. What is the expected result of executed the following code?

    def fun(n):
       s = '+'
       for i in range(n):
         s += s
         yield s
    for x in fun(2):
        print(x, end='')
    • It will print+++
    • It will print ++
    • It will print ++++++
    • It will print +
  11. What is the meaning of the value represented by errno.EEXITS ?

    • File doesn’t exist
    • Bad file number
    • Permission denied
    • File exists
  12. What is the expected result of the following code?

    b = bytearray(3)
    print(b)
    • 3
    • bytearray(b'\x00\x00\x00')
    • bytearray(0, 0, 0)
    • bytearray(b'3')
  13. What is the expected output of the following code?

    from datetime import datetime
    datetime = datetime(2019, 11, 27, 11, 27, 22)
    perint(datetime.strftime('%y/%B/%d %H:%M:%s'))
    • 19/November/27 11:27:22
    • 2019/Nov/27 11:27:22
    • 2019/11/27 11:27:22
    • 19/11/27 11:27:22
  14. What is the expected output of the following code?

    import os 
    os.mkdir('pictures')
    os.chdir('pictures')
    os.mkdir('thumbnails')
    os.chdir('thumbnails')
    os.mkdir('tmp')
    os.chdir('../')
    print(os.getcwd())
    • The orint to the thumbnails directory
    • The path to the  pitcures directory 
    • The path to the tmp directory
    • The path to th root directory
  15. What is the expected output of the following code?

    import os
    os.mkdir('thumbnails')
    os.chdir('thumbnails')
    sizes = ['small', 'medium', 'large']
    for size in sizes:
        os.mkdir(size)
    print(os.listdir())
    • ['.', '..', 'large', 'small', 'medium']
    • []
    • ['.', 'large', 'small', 'medium']
    • ['large', 'small', 'medium']
  16. What is the expected result of the following code?

    import calendar
    c = calendar.Calendar()
    for weekday in c.iterweekdays():
        print(weekday, end="")
    • 1 2 3 4 5 6 7
    • Su Mo Tu We Th Fr Sa
    • 0 1 2 3 4 5 6 7
    • Mo Tu We Th Fr Sa Su