Python Exam 2

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

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)

'Mon Jan 17 10:45:12 2022'

In regular expression, ________ matches the start of the string, and ________ matches the end of the string.

'^', '$'

Which one does not belong to Pycryptodome in Python?

CEO

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

False

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

.exe

What will be the output of the following Python code? str = 'abcd' for i in str: print(i.upper())

A B C D

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?

220

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

3 2 1 c b a

What is the output of print len( [ 'abcd', 786 , 2.23, 'john', 10 ] )?

5

What will be the output of the following Python program? i = 5 while i > 0: print(i)i -=1 if i == 3: break else: print(0)

5 0 4

Suppose dictionary d1 = {"Susan":42, "John":40, "Peter":45} To get Susan's age, what command do we use?

d1.get("Susan")

Which keyword is used for function in Python language?

def

Which of the following is an example of Python function prototype that takes variable number of arguments

def add(*num):

To open a file c:\scores.txt for appending data, we use ____________

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

What is the output of print str[2:5] if str = 'Python Programming'?

tho

Which of the following is used to define a block of code in Python language?

Indentation

Which encoding statement is invalid?

None of them

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)

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

Suppose dictionary d1 = {"Susan":42, "John":40, "Peter":45} to delete the entry for "john" what command do we use?

del d1["John"]

Which of built-in function in python accepts user input?

input()

What command shall we use to install pycryptodome in our Python project

pip install pycryptodome

What is the output of the following of Python code fragment? from datetime import datetime timestamp = [1591682671] for unix_time in timestamp: print(datetime.utcfromtimestamp(unix_time).strftime('%Y-%m-%d %H:%M:%S'))

2020-06-09 06:04:31

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

50

What is the output of the following Python code fragment def compute(a): return a + 1 print(compute(7) * compute(6))

56

What will be the output of the following code? import random random.randint(1,5)

Any integer between 1 and 5, including 1 and 5

One important benefit of importing the sys modules as "import sys"; instead of, "from sys import *" is ?

It limits namespace conflict issues

What does secrecy mean in secure communication?

Only intended receiver understands the message

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

[ ]

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

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

What is the output of the following python code fragment? values = [x**2 for x in range(0, 11)] print(values)

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

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

b c

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?

list1.extend(list2)

Which Scapy command is used to identify all available parameters for the IP method?

ls(IP)

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?

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?

myfile.close()

What command shall we use to install Faker module in our Python project?

pip3 install Faker

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

rstrip()

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

we are humans

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()

155f2a75a142700989fe1c2f2919802a

Assume today is 2/21/2022, Monday, what output for the following code? import datetime d=datetime.date(2016,3,15) print(d) tday=datetime.date.today() print(tday) print( tday.weekday() ) print( tday.month )

2016-03-15 2022-02-21 0 2

Which of the following is not a core data type in Python programming?

Clsss

What will be the output of the following Python code? import time time.asctime()

Current date and time

What will be the output of the following code? import random random.choice(['A','B','C', 1, 2, 3])

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

Does python code need to be compiled or interpreted?

Python code is both compiled and interpreted

About Python module, which statement is Not correct?

Python module is package.

What is the output of m.group(0) in the following Python code fragment:

Shell

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?

The above actions are invalid for updating tuple

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

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

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

True

In Python, all elements in a set data structure must be hashable

True

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

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

What output will be generated from the following python code fragment?

b'TWFsd2FyZSwgeW91IGNhbiBydW4gYnV0IHlvdSBjYW4ndCBoaWRl'

Which of the following is not a valid way to define Python's dictionary?

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

What is the output of print str[2: ] if str = 'Python Programming'?

thon Programming

What is the purpose of the keyword 'pass' in the following Python function: def empt_function(): pass

to tell Python to do nothing

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 )

['we are humans']

To import AES module for encoding, what do you need to consider about?

-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--

What requirement is for secure communication?

-Secrecy -Authentication -Message Integrity --All of them--

Which function call is allowed for the following function? def getProduct(*args): product = 1 for arg in args: product*=arg return product

-print(getProduct()) -print(getProduct(10, 20,40)) -print(getProduct(-10, -23,-46)) --All of them--

Which of the following is the correct extension of the Python file?

.py

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

0 1 2

What will be the output of the following Python code? str = 'abcd' for i in range(len(str)): print(i)

0 1 2 3

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

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)

1 3

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

12

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

2

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))

What is your secret?{{{{

What will be the output of the following code? re.split(r'(a)(t)', 'Test Math today')

['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)))

[('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*x print( list( map(foo, mylist) ) )

[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)

[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])

[1, 7]

To read the entire remaining contents of the file as a string from a file object myfile, we use ____________

myfile.read()

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

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

Which of the following functions is a built-in function in python?

print()

Which module in Python supports regular expressions?

re

Which of the following is not python's built-in function

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 re openemail = open('students_email.txt', 'r') email_pattern = _______________________________________ matches = email_pattern.finditer(openemail.read()) for match in matches: print(match.group())

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


Set pelajaran terkait

US History 1 Final Open Responses

View Set

HESI Comprehensive B, Comprehensive Exam A, 2020 exit v 2 ?????

View Set

Gr 4 - Social Studies - Chapter 8 - Review Q&A

View Set

Controlling Microbial Growth in the Environment

View Set

Vocab Semester Final Unit 7, 8, 9 Level G

View Set