Exam 2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

Does python code need to be compiled or interpreted? Question options: Python code is both compiled and interpreted Python code is neither compiled nor interpreted Python code is only compiled Python code is only interpreted

Python code is both compiled and interpreted

What will be the output of the following Python code? wordtest = re.compile('[A-Za-z]+')print( wordtest.findall('It will rain today') ) Question options: It will rain today ('It will rain today') ['It will rain today'] ['It', 'will', 'rain', 'today']

['It', 'will', 'rain', 'today']

To open a file c:\scores.txt for appending data, we use ____________ Question options: outfile = open("c:/scores.txt", "r") outfile = open("c:/scores.txt", "w") outfile = open("c:/scores.txt", "a") outfile = open("c:/scores.txt", "rw")

outfile = open("c:/scores.txt", "a")

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.group()) Question options: we are humans ('we', 'humans') (we, are, humans) ('we', 'are', 'humans')

we are humans

What will be the output of the following code? import randomrandom.choice(['A','B','C', 1, 2, 3]) Question options: Error Either of 'A', 'B', or 'C', excluding 1, 2, 3 Either of 1, 2, or 3, excluding 'A', 'B', 'C' Either of 'A', 'B', 'C', 1, 2, or 3

Either of 'A', 'B', 'C', 1, 2, or 3

What will be the output of the following Python code? import time t=(2022, 1, 17, 10, 45, 12, 7, 0, 0) time.asctime(t) Question options: '10:45:12 2022 Jan 17 Mon' '10:45:12 2022 Mon Jan 17' 'Mon Jan 17 10:45:12 2022' 'Jan 17 10:45:12 2022 Mon'

'Mon Jan 17 10:45:12 2022'

In regular expression, ________ matches the start of the string, and ________ matches the end of the string. Question options: '^', ' . ' '^', '?' '^', '$' '^', '*'

'^', '$'

What is the content of pinSHA512 in the following python code : import hashlib salt = 'Python Scripting for Cybersecurity' pin = 43523423232332 pinSHA512 = hashlib.md5((str(salt)+str(pin) + str(salt)).encode('utf-8')).hexdigest() Question options: b9df5cb9c1bb68d86a447341ccddf905 4cfb653a3babbad83685166a49949d5ec4198226e4921597c3e642f23b1d4526 155f2a75a142700989fe1c2f2919802a 275ffbbd0a75abea74922732f92ae74573d9231e

155f2a75a142700989fe1c2f2919802a

What will be the output of the following Python code? for i in ['a', 'b', 'c', 1, 2, 3][::-1]: print (i) Question options: a b c 1 2 3 a b c 3 2 1 3 2 1 c b a

3 2 1 c b a

What is the output of print len( [ 'abcd', 786 , 2.23, 'john', 10 ] )? Question options: [ 'abcd', 786 , 2.23, 'john', 10 ] 10 5 Error

5

What will be the output of the following Python program? i = 5while i > 0:print(i)i -=1if i == 3:breakelse:print(0) Question options: 5 4 3 2 1 5 4 3 5 4 5 0 4

5 0 4

What is the output of the following Python code? func = lambda x: x+20 print( func(5*6) ) Question options: x 20 30 50

50

What will be the output of the following Python code? str = 'abcd' for i in str: print(i.upper()) Question options: a b c d A B C D A b c d None of them

A B C D

What requirement is for secure communication? Question options: Secrecy Authentication Message Integrity All of them

All of them

Which function call is allowed for the following function? def getProduct(*args):product = 1for arg in args:product*=argreturn product Question options: print(getProduct()) print(getProduct(10, 20,40)) print(getProduct(-10, -23,-46)) All of them

All of them

What will be the output of the following code? import randomrandom.randint(1,5) Question options: Any integer between 1 and 5, including 1 and 5 Any integer between 1 and 5, excluding 1 and 5 None

Any integer between 1 and 5, including 1 and 5

Which one does not belong to Pycryptodome in Python? Question options: AES ECB CBC CEO

CEO

What will be the output of the following Python code? import time time.asctime() Question options: Current date only Current time only Current date and time UTC time

Current date and time

The main objective of adding salt to hashing is to improve data integrity

False

Which of the following is used to define a block of code in Python language? Question options: Reserved key Indentation Brackets [ ] Parentheses ( )

Indentation

Given the following tuple: my_tuple = (5, 10, 15, 25, 30) Suppose you want to update the value of this tuple at 3rd index to 20. Which of the following option will you choose? Question options: my_tuple[3]=20 my_tuple(3)=20 my_tuple.insert(3, 20) The above actions are invalid for updating tuple

The above actions are invalid for updating tuple

What command shall we use to install pycryptodome in our Python project Question options: install pip pycryptodome pip install pycryptodome import pycryptodome include pycryptodome

pip install pycryptodome

What will be the output of the following Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups()) Question options: 'we are humans' ('we', 'humans') (we, are, humans) ('we', 'are', 'humans')

('we', 'are', 'humans')

What will be the output of the following Python program? i = 0while i < 5:print(i)i += 1if i == 3:break Question options: 0 1 2 3 4 0 1 2 3 0 1 2 0

0 1 2

What will be the output of the following Python code? str = 'abcd' for i in range(len(str)): print(i) Question options: a b c d a b c 1 2 3 4 0 1 2 3

0 1 2 3

What output of result in following Python program? list1 = [1,2,3,4]list2 = [2,4,5,6]result1 = list1 + list2for i in result1:print(i) Question options: 1 2 3 4 2 4 5 6 1 2 3 4 2 4 5 6 1 2 3 4 5 6

1 2 3 4 2 4 5 6

What output in following Python program? list1 = [1,2,3,4]list2 = [2,4,5,6]list3 = [2,6,7,8]result1 = list1 + list2result2 = list2 + list3for i in result1:if i not in result2:print(i) Question options: 1 2 3 4 2 4 5 6 2 4 5 6 2 6 7 8 1 3 7 8

1 3

What is the output of the following of Python code fragment? from datetime import datetimetimestamp = [1591682671]for unix_time in timestamp:print(datetime.utcfromtimestamp(unix_time).strftime('%Y-%m-%d %H:%M:%S')) Question options: 2019-10-21 08:38:35 2020-06-09 06:04:31 2019-10-21 09:05:33 2019-12-21 09:05:33

2020-06-09 06:04:31

What output will be generated from the following Python program? BLOCK_SIZE=24 PAD="{" secret_info="What is your secret?" padding= lambda s: s + (BLOCK_SIZE - len(secret_info) % BLOCK_SIZE) * PAD print(padding(secret_info)) Question options: What is your secret? What is your secret?{{ What is your secret?{{{{ What is your secret?{{{{{{{{{{{{

What is your secret?{{{{

What will be the output of the following code? re.split(r'(a)(t)', 'Test Math today') Question options: 'Test Math today' ['Test Math today'] ['Test M', 'a', 't', 'h today'] ['T', 'e', 's', 't', 'M', 'a', 't', 'h', 't', 'o', 'd', 'a', 'y']

['Test M', 'a', 't', 'h today']

zip() function is used to transform multiple lists into a single list of tuples by taking the corresponding elements of lists that are passed as parameter. What is the out put of the following python code fragment: x = ["A", "B", "A", "C", "A"]y = ["Bash", "Python", "Powershell"]print(list(zip(x,y))) Question options: [('A', 'Bash'), ('B', 'Python'), ('A', 'Powershell')] [('A', 'Bash'), ('B', 'Python'), ('A', 'Powershell'), C, A] [('A', 'Bash'), ('B', 'Python'), ('A', 'Powershell'), ('C', 'Scripting'), ('A', 'Programming')] [('A', 'Bash'), ('B', 'Python'), ('A', 'Powershell'), "C", "A"]

[('A', 'Bash'), ('B', 'Python'), ('A', 'Powershell')]

What will be the output of the following code? mylist = [0, 1, 3, 5]def foo( x ):return x*xprint( list( map(foo, mylist) ) ) Question options: [ 0 ] [0, 1, 3, 5] [0, 1, 6, 10] [0, 1, 9, 25]

[0, 1, 9, 25]

What will be the value of 'result' in following Python program? list1 = [1,2,3,4]list2 = [2,4,5,6]list3 = [2,6,7,8]result = list()result.extend(i for i in list1 if i not in (list2+list3) and i not in result)result.extend(i for i in list2 if i not in (list1+list3) and i not in result)result.extend(i for i in list3 if i not in (list1+list2) and i not in result)print(result) Question options: [1, 2, 3, 4, 5, 6, 7, 8] [1, 7 ,8] [1, 2, 4, 7, 8] [1, 3, 5, 7, 8]

[1, 3, 5, 7, 8]

What is the output of the following python code fragment?: list1 = [1, 2, 5, 7]list2 = [4, 2, 5, 3]print([i for i in list1 if i not in list2]) Question options: [1 2 5 7] [4, 2, 5, 3] [1, 7] [3, 4]

[1, 7]

What is the output of the following python code fragment? def fun(list):list[0] = 5return listmylist = [10,11,12]print(fun(mylist), mylist) Question options: [5, 11, 12] [10, 11, 12] [5, 11, 12] [5, 11, 12] [10, 11, 12] [10, 11, 12] [10, 11, 12] [5, 11, 12]

[5, 11, 12] [5, 11, 12]

Suppose dictionary d1 = {"Susan":42, "John":40, "Peter":45} to delete the entry for "john" what command do we use? Question options:d1.delete("John")d1.delete("John":40)del d1["John"]del d1("John")

del d1["John"]

Which of the following is not a valid way to define Python's dictionary? Question options:dic = {'Albert': 23, 'Mary': 23, 'Simon': 43}dic = {('Albert': 23), ('Mary': 23), ('Simon': 43)}dic= {}dic['Albert'] = 23dic['Mary'] = 23dic['Simon'] = 43dic= dict([('Albert', 23),('Mary' , 23),('Simon',43)])

dic = {('Albert': 23), ('Mary': 23), ('Simon': 43)}

Which of built-in function in python accepts user input? Question options: Read-Host input() import() read()

input()

Want to add 20 at 3rd place in my_tuple my_tuple = (5, 10, 15, 25, 30) And update the tuple as (5, 10, 15, 20, 25, 30) Which of the following code can help to realize the purpose? Question options:my_tuple[3] = 20my_tuple.insert(3, 20)mylist = list(my_tuple)mylist[3] = 20my_tuple = tuple(mylist)my_tuple = (5, 10, 15, 25, 30)mylist = list(my_tuple)mylist.insert(3, 20)my_tuple = tuple(mylist)

my_tuple = (5, 10, 15, 25, 30)mylist = list(my_tuple)mylist.insert(3, 20)my_tuple = tuple(mylist)

How do you close a file object myfile? Question options: close(myfile) fclose(myfile) myfile.close() myfile._close()_

myfile.close()

To read the entire remaining contents of the file as a string from a file object myfile, we use ____________ Question options: myfile.read() myfile.read(2) myfile.readline() myfile.readlines()

myfile.read()

What command shall we use to install Faker module in our Python project? Question options: install pip3 Faker pip3 install Faker import Faker include Faker

pip3 install Faker

Which of the following functions is a built-in function in python? Question options: randint( ) print() sqrt() factorial()

print()

What Python built-in function is used to removes characters from the end of the string that are present in the set of characters supplied to rstrip() (if passed, and not None). rstrip() stops as soon as a character in the string is found that is not in the set of stripping characters Question options: trim() lstrip() rstrip() all

rstrip()

What is the output of print str[2:5] if str = 'Python Programming'? Question options: ytho thon tho thon Programming

tho

What is the output of m.group(0) in the following Python code fragment: import rem = re.search(r'(?<=-)\w+', 'Power-Shell') Question options: 'Shell', 'Shell' ['Shell', 'Shell'] Shell None

Shell

Suppose the variable filename is equal to "C:\\Windows\System\powershell.exe", what would the filename[-4:] return? Question options: C:\\Windows\System\powershell.exe powershell C:\\ .exe

.exe

Which of the following is the correct extension of the Python file? Question options: .python .p .py .ps

.py

Assume today is 2/21/2022, Monday, what output for the following code? import datetimed=datetime.date(2016,3,15)print(d)tday=datetime.date.today()print(tday)print( tday.weekday() )print( tday.month ) Question options: 2016-03-152022-02-2102 2016-03-152022-02-2112 2016-03-152022-02-2132 2016-03-152022-02-2162

2016-03-152022-02-2102

What is the output of the following Python's code fragment: mylist = [-12, -43, 55, 67, -32, 12, -2]print( mylist[-2] ) Question options: -2 12 55 Error

12

What will be the output of the following Python code? def foo():try:if x == 10:return 1finally:return 2x = 10result = foo( )print( result ) Question options: 1 2 10 None

2

When converting a string or a file into base64, on average, the encoded file generally increases the file size between 133-137% of the original file. (For instance, the base64 encoded form of the string "Script Programming" is "U2NyaXB0IFByb2dyYW1taW5nCg==". ) Suppose that the Base64 encoded file size is 300MB. What is the the approximate file size of the original document? Question options: 180 220 330 400

220

What is the output of the following Python code fragment def compute(a):return a + 1print(compute(7) * compute(6)) Question options: 56 42 14 None

56

To import AES module for encoding, what do you need to consider about? Question options: Create a fixed size of key for the password Plaintext or secret information should be put on a fixed block size Padding is used to achieve fixed size block Hashing is used to map data and produce a random-like fixed-length output (called digest or hash value) by cryptographic hash function All of them

All of them.

Which of the following is not a core data type in Python programming? Question options: Number, String, Boolean List, Tuple Dict, Set Clsss

Class

One important benefit of importing the sys modules as "import sys"; instead of, "from sys import *" is ? Question options: It improves efficiency It limits namespace conflict issues It is a convenient sys method calling It enhances program security

It limits namespace conflict issues

Which encoding statement is invalid? Question options: import base64 base64.b64encode(b 'text message') import base64 base64.b32encode(b 'text message') import base64 text="text message" base64.b64encode( text.encode('utf-8') ) import base64 text="text message" base64.b32encode( text.encode('utf-8') ) None of them

None of them.

What does secrecy mean in secure communication? Question options: Both sender and receiver understand the message Only intended receiver understands the message Sender and receiver need to confirm each others identity None of them

Only intended receiver understands the message

About Python module, which statement is Not correct? Question options: A module is a packaged collection of Python functions, scriptsModules must be imported into Python sessionsExternal modules, generally installed (pip3 install moduleX) and imported (import moduleX) Python module is package.

Python module is package.

A hash function is any function that can be used to map data of arbitrary size to fixed-size values Question options:TrueFalse

True

In Python, all elements in a set data structure must be hashable Question options:TrueFalse

True

What will be the output of the following Python function? sentence = 'we are humans'matched = re.findall('we are humans', 'we are humans', 1)print( matched ) Question options: [ ] 'we are humans' ['we are humans'] None

['we are humans']

What is the content of mylist in the following Python's code fragment? mylist = [-12, -43, 55, 99, -32, 12, -2]mylist.insert(2, 67) Question options: [-12, -43, 55, 99, -32, 12, -2, 2, 67] [2, 67, -12, -43, 55, 99, -32, 12, -2] [-12, -43, 67, 55, 99, -32, 12, -2] [-12, 67, -43, 55, 99, -32, 12, -2]

[-12, -43, 67, 55, 99, -32, 12, -2]

What is the output of the following python code fragment? values = [x**2 for x in range(0, 11)]print(values) Question options: [0, 2, 4, 8, 10, 12, 14, 16, 18, 20, 22] [1, 2, 4, 9, 16, 25, 36, 49, 64, 81, 100] [0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100] [0, 1, 4, 9, 16, 25, 36, 49, 81, 100, 121]

[0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100]

What will be the output of the following Python function? sentence = 'we are humans'matched = re.findall('we are humans', 'we', 1)print( matched ) Question options: [ ] ['we'] we [ 'we are humans' ]

[]

What will be the output of the following Python code? for i in ['a', 'b', 'c', 1, 2, 3][1:3]: print (i) Question options: 1 3 1 2 3 b c a b c

b c

What output will be generated from the following python code fragment? import base64 secret_data = "Malware, you can run but you can't hide" b64encoded_data = base64.b64encode( secret_data.encode('utf-8') ) print(b64encoded_data) Question options: b'VGhpcyBpcyBteSBmaW5hbCBxdWl6MQ==' b'TWFsd2FyZSwgeW91IGNhbiBydW4gYnV0IHlvdSBjYW4ndCBoaWRl' b'VGhpcyBpcyBvdXIgZmluYWwgcXVpeg==' b'SXQgaXMgbXkgbmFtZSBub3QgdGhlIHNlY3JldCBkYXRh'

b'TWFsd2FyZSwgeW91IGNhbiBydW4gYnV0IHlvdSBjYW4ndCBoaWRl'

Suppose dictionary d1 = {"Susan":42, "John":40, "Peter":45} To get Susan's age, what command do we use? Question options:d1.keys()print(d1.values())d1.get("Susan")d1.get(42)

d1.get("Susan")

Which keyword is used for function in Python language? Question options: function def method None of above

def

Which of the following is an example of Python function prototype that takes variable number of arguments Question options: def add(num): def add(*num): def add(*num*): def add(num...):

def add(*num):

Assume, you are given two lists: list1 = [1,2,3,4,5] list2 = [6,7,8,9,10] Your task is to update list1 which has all the elements of list1 and list2. Which of the following python statement would you choose? Question options: list1.append(list2) list1.extend(list2) list1.pop(list2) list1 + list2

list1.extend(list2)

Which Scapy command is used to identify all available parameters for the IP method? Question options: show(IP) ls(IP) help(IP) method(IP)

ls(IP)

Your friend is very proud of her new laptop password. She says you can guess as many times as you like. You know that the password contains only numbers and that the password is 8 characters long. Which Python code fragment allows you to brute force the password Question options:password = "89472456"for i in range(100000000):i = f'{i:06}'if i == password:print("Password is correct", i, password)breakpassword = "12345678"for i in range(100000000):i = f'{i:08}'if i == password:print("Password is correct", i, password)breakpassword = "12345678"for i in range(100000000):i = f'{i:09}'if i = password:print("Password is correct", i, password)breakpassword = "89472456"for i in range(10000000):i = str(i).zfill(7)if i = password:print("Password is correct", i, password)break

password = "12345678"for i in range(100000000):i = f'{i:08}'if i == password:print("Password is correct", i, password)break

Which module in Python supports regular expressions? Question options: re regex regular don't know

re

Which of the following is not python's built-in function Question options: hash() zip() re() bin()

re()

Choose the best regular expression pattern that completes this code to match all ung students' emails listed in the 'students_email.txt' text file. import reopenemail = open('students_email.txt', 'r')email_pattern = _______________________________________matches = email_pattern.finditer(openemail.read())for match in matches:print(match.group()) Question options: re.compile(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+\.(edu)') re.compile(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+\.(\w)') re.compile(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+\.(\w\w)') re.compile(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+\.\d{3}')

re.compile(r'[a-zA-Z0-9]+@[a-zA-Z0-9]+\.(edu)')

What is the output of print str[2: ] if str = 'Python Programming'? Question options: y t thon thon Programming

thon Programming

What is the purpose of the keyword 'pass' in the following Python function: def empt_function():pass Question options: to pass the return value to the output to tell Python to do nothing to provide the memory address to create lambda expression

to tell Python to do nothing


Kaugnay na mga set ng pag-aaral

N257 Jeopardy and quiz questions

View Set

MICRO mastering infectious diseases

View Set

Qualified Plans and Federal Tax Considerations for Life Insurance and Annuities

View Set

Multiplying Polynomials and Simplifying Expressions

View Set