testimony 2

Ace your homework & exams now with 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'

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 Python code? sentence = 'we are humans' matched = re.match(r'(.*) (.*?) (.*)', sentence) print(matched.groups())

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

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

.exe

Which of the following is the correct extension of a 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 is the output in the following Python program? list1 = [1,2,3,4] list2 = [2,4,5,6] list3 = [2,6,7,8] result1 = list1 + list2 result2 = list2 + list3 for 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 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

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

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

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

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 the following Python code? func = lambda x: x+20 print( func(5*6) )

30

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

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 Python code? str = 'abcd' for i in str: print(i.upper())

A B C D

Regarding Python modules, which statement is incorrect?

A Python module is package.

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

All of them.

What requirement is for secure communication?

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

All of them.

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.

Which one does not belong to pycryptodome in Python?

CEO.

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

True or False: 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?

Indentation

Does Python code need to be compiled or interpreted?

It is both compiled and interpreted.

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

It limits namespace conflict issues.

Which encoding statement is **invalid?**

None of them.

What does secrecy mean in secure communication?

Only intended receiver understands the message.

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

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 is the purpose of the keyword 'pass' in the following Python function: def empt_function(): pass

To tell Python to do nothing.

True or False: A hash function is any function that can be used to map data of arbitrary size to fixed-size values.

True.

True or False: In Python, all elements in a set data structure must be hashable.

True.

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 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 will be the output of the following code? re.split(r'(a)(t)', 'Test Math today')

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

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

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]

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

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

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

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

^, $

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

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)

b'TWFsd2FyZSwgeW91IGNhbiBydW4gYnV0IHlvdSBjYW4ndCBoaWRl'

Suppose the following 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 functions in Python?

def

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

def add(*num):

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

del d1["John"]

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

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

Which built-in function in Python accepts user input?

input()

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)

Let's say you 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()

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

myfile.read()

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

thon Programming

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

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

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

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

What command shall we use to install pycryptodome on Python?

pip install pycryptodome

What command shall we use to install the Faker module on Python?

pip3 install Faker

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 a built in Python 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)')

What Python built-in function is used to remove characters from the **end** of the string that are present in the set of characters?

rstrip()


Related study sets

Inquizitive: Chapter 17. Social Policy

View Set

Entrepreneurship and Small Business Management

View Set

Chapter 3 - Breathing Gas and the Effects on Your Body

View Set

Immuny - ćw 5 (najważniejsze zagadnienia)

View Set

Social Problems SOCI-202 Midterm

View Set

Viet Deck Dental Anatomy/Occlusion-- Anterior teeth information

View Set

Supa Economic-Chapters 7, 9, 10 Review

View Set