Script Programming Exam 2

अब 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) Question options:

'Mon Jan 17 10:45:12 2022'

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

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

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

(T/F) The main objective of adding salt to hashing is to improve data integrity

False

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

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

All of them

Which one does not belong to Pycryptodome in Python?

CEO

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?

Python code is both compiled and interpreted

About Python module, which statement is Not correct? A module is a packaged collection of Python functions, scripts Modules must be imported into Python sessions External modules, generally installed (pip3 install moduleX) and imported (import moduleX) Python module is package.

Python module is package.

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

(T/F) A hash function is any function that can be used to map data of arbitrary size to fixed-size values

True

(T/F) In Python, all elements in a set data structure must be hashable

True

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

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

del d1["John"]

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

input()

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 is the output of print str[2:5] if str = 'Python Programming'?

tho

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 program? i = 5 while i > 0: print(i) i -=1 if i == 3: break else: print(0)

5 0 4

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): def add(*num): def add(*num*): def add(num...):

def add(*num):

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

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

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

to tell Python to do nothing

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

Shell

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

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

All of them

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 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 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-152022-02-2102

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

50

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 of the following is not a core data type in Python programming? Number, String, Boolean List, Tuple Dict, Set Clsss

Clsss

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

Only intended receiver understands the message

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

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 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 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 dictionary d1 = {"Susan":42, "John":40, "Peter":45} To get Susan's age, what command do we use? d1.keys() print(d1.values()) d1.get("Susan") d1.get(42)

d1.get("Susan")

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

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

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

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[3] = 20 my_tuple.insert(3, 20) mylist = list(my_tuple) mylist[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)

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

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 in our Python project

pip install pycryptodome

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

pip3 install Faker

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

print()

Which module in Python supports regular expressions?

re

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

re()

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 is the output of print str[2: ] if 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


संबंधित स्टडी सेट्स

NUR 209 Ch. 23 Asepsis (Fundamentals of Nursing)

View Set

Microbiology, Ch 26, Nester's 9th

View Set

Regulations: Securities Exchange Act of 1934

View Set

Personal Fitness Chapter 3 Lesson 2

View Set

ES 391: Chocolate Milk: A Post- Exercise Recovery Beverage for Endurance Sports

View Set

Asepsis and Infection Control- Gero

View Set

HIST 11 - Compilation of Quiz Questions

View Set