god help me for i am about to fail

¡Supera tus tareas y exámenes ahora con Quizwiz!

Which of the following statements are true of the Python shebang? Each correct answer represents a complete solution. Choose all that apply.

It is portable between Unix and Windows. It is the first line of a script file. It starts with #!.

Rosy, a Python programmer, wants to check skills of an intern in Python programming, who is recently hired in the company. She has written the following code and asked: f = open("file.txt", "w") f.close() What will the given code do?Each correct answer represents a complete solution. Choose all that apply.

It will open the file file.txt in write mode. It will delete the file contents if the file file.txt already exists. It will create the file file.txt if it does not exist.

Which of the following data types is mutable in the Python language?

List

Dev is a software developer in the XYZ company. He has been asked to create an application on short notice as his company has a sudden deal with a client. Which of the following programming languages will Dev use to save their time? A Python B C C C++ D Java

Python

Consider the following Python code: s = 'SPAM' def f(s): return s + 'MAPS' print(f(s)) What will be the output of the given code?

SPAMMAPS

Which of the following data structures is a collection which is unordered and unindexed and allows no duplicate members in the Python language? A Set B Tuple C List D Dictionary

Set

Consider the following code including the lambda function: double = lambda x: x * 2 print(double(5)) What will be the output of the given code?

10

Consider the following Python code: s = 5 a = lambda s: 1 + 2 print(a(s)) What will be the output of the given code?

3

What will be the output of the given Python arithmetic expression? print(4*(2+3)**3 - (3**3)*4)

392

Consider the following Python code: a = 2 b = a ** 2 if b < a + 1: c = 1 elif b == 1: c = 2 else: c = 3 print(a+b+c) What will be the output of the given code?

9

George is learning the Python language. His instructor has asked him to write a code to check whether a number is even or odd. He has written the following code: x = int(input('Enter a number: '))while x%2 == 0 print('You have entered an even number.')else: print ('You have entered an odd number.') What will be the output of the given code if the entered number is 12?

A SyntaxError is raised at line 2.

Question 31 : Andy works as a Python programmer in a company. He has written the following program: while True: try: a = 4 + x * 3 print(a) break except(RuntimeError, ValueError, TypeError, NameError): pass What will be the output of the program?

A null operation will be generated.

Devin is a Python developer in a company. He has been asked by the senior developer of his company to work on a code based on the comparison operator in Python and find out the output. He has the following code: x = "20" y = "30" print(x>y) Which output will Devin get from the code?

False

Aaron is writing a program in the Python language in which he needs to assign values to the variables using the assignment operator. He has the following code: x = 12 y = 5 x =+ 5 print(x) He wants the output value of the variable x as 17 but on executing the given code, the output value of the x variable comes as 5. What is the issue in the given code?

The assignment operator is incorrect in the expression.

You are learning Python. You have been taught about the packages in Python. Now, your instructor wants to test your knowledge and asks a question about the __init__.py files which are used in packages. Which of the following statements are true about the __init__.py files?

These files set the __all__ variable. These files indicate that the directories are containing packages and modules. These files execute the initialization code for the package.

list = ['a', 'b', 'c', 'd', 'e', 'f'] del list[0:-2] print(list) What will be the output of the given code?

['e', 'f']

Ethan is a software developer in the ABC company. He is creating an application based on the Python language in which he has to generate a random integer with a minimum value of 5 and a maximum value of 11. Which two functions should Ethan use to achieve the given task?

andom.randint(5, 11) random.randrange(5, 12, 1)

Ethan is a programmer in the ABC company. He is writing a Python program and wants that the program should print the output as the two asterisks in two separate lines. Which of the following lines of code will Ethan use to accomplish his task?

for i in range(1, 4, 2): print("*")

John is an expert in the Python language. He asked to explain some basic programming concepts to the beginners. He has to introduce the concept of data types in Python. He has created the following code segment as an example to explain the concept: x = "20" y = 3 a = x * y print(type(a)) After executing the code segment, which of the following data types will John get as a result?

str

Mark works as a software developer in UC Inc. He is developing an application based on the Python language in which he has created a file named test.txt. Now, he wants to open the file and display its content. He has written the following code: for line in open("test.txt"): print(line, end="") The file gets executed and displayed properly but is not closed properly. Which of the following code segments should Mark use to avoid this issue?

with open("test.txt") as f: for line in f: print(line, end="")

What will be the output of the following code? import sys sys.ps1

'>>> '

Consider the following Python code: a = 1+2j print(a, "is a complex number?", isinstance(1+2j,complex)) What will be the output of the given code?

(1+2j) is a complex number? True

Jenny is working as a SME in the XYZ company. She has created different types of questions in many courses. She is asked to find the count of particular type of questions created by her in all the courses to ensure that there is a good balance of questions. She takes help of a Python developer of her company to make a program which can easily count the number of questions. The developer has written the following code: def count_ques(ques, course_list): count = 0 for : if : count += 1 return count course_list = [] # function accepts the list of courses and questions to search for from a file ques = input("Enter the type of question to count: ") ques_count = count_ques(ques, course_list) print("There are", ques_count," number of "+ ques) Which of the following conditions will the Python developer use to complete the given code?

(course in course_list), (ques in course)

Ethan is working as a Python programmer in a company. He has been asked to write a program and he has to perform a loop through dictionaries and at the same time retrieve the key and its corresponding value. Which of the following looping methods will Ethan use for this purpose?

items()

Rena, a python programmer, writes a code in the Python language to access the test.txt file and retrieve each line in it. She has written the following code: file = open(test.txt) # put the line of code here file.close() Which of the following code segments will Rena use?Each correct answer represents a complete solution. Choose all that apply.

print(file.readlines()) print(list(file)) print(file.read())

Oliver is a Python programmer. He is writing a program and he wants the output 123456 to be printed horizontally. He has the following code: n = 0 while n < 6: n += 1 # Write the code here Which line of code will Oliver use to print the desired output?

print(n, end=" ")

A Python developer is creating an application using dynamic formatting whose output should be in the following format: **cat** 123.24 The developer has written the following code: string = "{:{fill}{align}{width}}" # Write the code here num = "{:{align}{width}.{precision}f}" # Write the code here Which of the following sets of code segments will the developer use to print the desired output?

print(string.format('cat', fill='*', align='^', width=7)) print(num.format(123.236, align='<', width=6, precision=2))

Which of the following functions of the random module initializes the random number generator? A random.setstate(state) B random.getstate() C random.seed(a=None, version=2) D random.getrandbits(k)

random.seed(a=None, version=2)

William is recently hired as an intern Python programmer in the UCB company. He has been asked to write a program using Intermezzo coding style guide. Which of the following points should not be used by him while writing the program? A Name the classes and functions consistently. B Wrap lines of code to avoid exceeding 79 characters. C Use tabs for indentation instead of spaces. D Use docstrings or documentation strings.

Use tabs for indentation instead of spaces.

Jonas is a Python developer in the ABC company. He is creating a program to find out the largest of the three numbers. He has the following incomplete code: num1 = 10 num2 = 14 num3 = 12 if # Write the code here largest = num1 elif # Write the code here largest = num2 else: largest = num3 print("The largest number between",num1,",",num2,"and",num3,"is",largest) Which of the following lines of codes will be placed in the given code?Each correct answer represents a complete solution. Choose two.

(num2 >= num1) and (num2 >= num3): (num1 >= num2) and (num1 >= num3):

Consider the following Python code: for i, v in enumerate(['Jill', 'John', 'Jim', 'Jack', 'Johny']): print(i,v) What will be the output of the given code?

0 Jill 1 John 2 Jim 3 Jack 4 Johny

Steffan is a programmer in the ABC company. He is writing a program to calculate the HCF (highest common factor) of two numbers. He has the following code: def HCF(x, y): if x > y: smaller = y else: smaller = x for i in range(# Write the condition here): if (# Write the condition here): hcf = i return hcf n1 = 54 n2 = 24 print("The HCF of", n1,"and", n2,"is", HCF(n1, n2)) Which two conditions will Steffan use in the range() function of the for statement and in the if statement?

1, smaller+1 (x % i == 0) and (y % i == 0)

Consider the following Python code: i = 250 while len(str(i)) > 72: i *= 2 else: i //= 2 print(i) What will be the output of the given code?

125

William is a Python programmer in uCertify Inc. He has written the following program which will ask the users to enter a number until they guess the stored number correctly.Hint: Check whether the guessed number is greater than or less than the stored number (n). class Error(Exception): """Base class for other exceptions""" pass class NumberIsSmallError(Error): """Raised when the input value is small""" pass class NumberIsLargeError(Error): """Raised when the input value is large""" pass n = 10 while True: try: i_num = int(input("Enter a number:")) if i_num < n: raise NumberIsSmallError elif i_num > n: raise NumberIsLargeError break except NumberIsSmallError: print("The number is small, try again!") except NumberIsLargeError: print("The number is large, try again!") # put the guessed number here print("Congratulations! You guessed it correctly.") Which of the following will be the guessed numbers to print the output as The number is small, try again!?Each correct answer represents a complete solution. Choose two.

4 0

You are an instructor of the Python language. You are teaching your students about the loops in Python which included some important points on the infinite loop. Which of the following points should be followed to avoid the infinite loop in a while statement? A Always remember to put a colon at the end of the while statement. B Always remember to increment or decrement the variable. C Always remember to give an expected indentation in a while statement. D Always remember to keep one while statement inside the other.

Always remember to increment or decrement the variable.

You are a beginner in the Python language. You have learned about data type conversion in Python. You have written a program of division of variables whose output is coming in the int() data type but you want the output in the float() data type to get more acurrate result. Which of the following processes will you perform to convert the int() data type to the float() data type? A Importing B Serializing C Name mangling D Casting

Casting

George is a programmer working on the Python language. He has been asked to write a program in such a way so that he can explain it in brief to the tester of the program. Which of the following will George use to explain the program to the tester? A Comments B Quotations C Multi-line statements D Indentation

Comments

You are a Python programmer. You have written a code to compare two lists numlist and alphalist using comparison and identity operators. You have the following code: numlist = [1,2,3,4,5] alphalist = ['a','b','c','d','e'] print(numlist is alphalist) print(numlist == alphalist) numlist = alphalist print(numlist is alphalist) print(numlist == alphalist) What will you get as the output from all the four print statements? The outputs are comma seperated in the same order as the given code.

False, False, True, True

Rob, an HR executive of a company, wants to greet all the employees in the company. He asked the programmer to make a Python program for him for this purpose. The programmer has written the following code: def greet(*names): for name in names: print('Hello', name) greet('John', 'Jack', 'Rosy', 'Jenny') What will be the output of the following code?

Hello John Hello Jack Hello Rosy Hello Jenny

Consider the following Python code: try: print("Hello") raise Exception except Exception as e: print(e) What happens when the code is executed and an exception is raised?

One non-empty line and one empty line will be printed.

Which of the following is used for grouping in the Python expression?

Parenthesis

Consider the following Python code: detail = { 'John': 1, 'Jack': 2, 'Jim': 3 } for name in detail: print(name) What will be the output of the given code?

John Jack Jim

Consider the following Python code: drink = None food = 'Available' def menu(x): if x == drink: print(drink) else: print(food) menu(drink) menu(food) What will be the output of the given code?

None Available

Which of the following conventions are not applicable for creating an identifier in Python?Each correct answer represents a complete solution. Choose all that apply. A The first character of the identifier must be an alphabet or an underscore. B A Python keyword can be used in an identifier name. C The first character of the identifier can be a digit (0-9). D Identifier names are case-sensitive.

Python keyword can be used in an identifier name. The first character of the identifier can be a digit (0-9).

Which of the following data structures removes the duplicate items from it? A. Tuple B. List C. Dictionary D. Set

Set

Which of the following exceptions is the base class for all built-in exceptions except StopIteration and SystemExit? A StandardError B ArithmeticError C LookupError D EnvironmentError

StandardError

Edwin, works as a Python programmer in the ABC company. He is asked to write a program in which the input is taken from the user until a vowel is entered. He has written the following code: vowels = "aeiouAEIOU" while True: v = input("Enter a vowel: ") if v in vowels: print("Thank you!") break print("That is not a vowel. Try again!") If the user enters A, b, c letters as the input, what will be the output?

Thank you!

Which of the following statements are true of the Python language?Each correct answer represents a part of the solution. Choose three. A The __iter__() method returns an object. B The __next__() method raises an OverflowError exception. C The __doc__ attribute is a valid attribute to return the docstring. D The __init__() function is a class constructor or initialization method.

The __iter__() method returns an object. The __doc__ attribute is a valid attribute to return the docstring. The __init__() function is a class constructor or initialization method.

You are working as a Python programmer in a company. You are asked to write a program in which you have to define a function. Which of the following will you use as the first statement in a function which makes the program easier to understand? A The documentation string of the function B The function suite of the function C The return statement of the function D The def keyword followed by the function name and parentheses

The documentation string of the function

Consider the following Python code: n = float(input("Enter the number: ")) n_sqrt = n ** 0.5 print('The square root of %0.3f is %0.3f'%(n, n_sqrt)) What will be the output of the given code if the entered number is 8?

The square root of 8.000 is 2.828.

David is a Python programmer in a company. David is writing a program in which he has used the from...import* statement. What is the purpose of this statement?

To import everything in the module

Mark is hired as a Python developer in the ABC company. He has been asked to write a program based on list comprehensions. He has written the following code: print([(n1,n2) for n1 in ['a', 'b', 'c'] for n2 in ['c', 'b', 'd'] if n1==n2]) What will be the output of the given code?

[('b', 'b'), ('c', 'c')]

Jones is working as a Python developer in an IT company. He has great skills in Python programming. He wanted to execute a module that tells the operating system what code to execute when a program is invoked. Which of the following is needed for this purpose? A __main__ B __file__ C __pycache__ D __name__

__main__

John is a Python developer in his company. He is developing an application in which he has to use some identifiers. Which of the following identifiers will John use according to the identifier naming conventions of the Python language? A. my-func B. 2func C. _myfunc D. my func

_myfunc

You are a Python developer in a company. You have assigned a program to one of your interns and discovered that the intern was working on a wrong directory. Therefore, you instructed the intern to revise the directory. Which of the following methods will the intern use for this? A chdir() B remove() C rmdir() D rename()

chdir()

You are a Python programmer. You are writing a program in which the day of the week should be returned as an integer, where Monday is 0 and Sunday is 6. Which of the following functions will you use for this purpose? A date.isoformat() B date.isoweekday() C date.weekday() D date.isocalendar()

date.weekday()

Which of the following are the correct rules for writing identifiers? Each correct answer represents a complete solution. Choose all that apply.

dentifiers can be a combination of letters, digits, and an underscore (_). Keywords cannot be used as identifiers. An identifier can be of any length.

Ryan is a Python programmer in a company. He has created the following dictionary dict of a manufactured car: dict = {"brand": "Ford", "model": "Mustang", "year": 1964} By mistake, he has added the wrong manufacturing year of the car. Now, he wants to change the year 1964 to 2018. Which of the following code segments will Ryan use?

dict["year"] = 2018 print(dict)

As a Python developer of your company, you have to create an application in which the names of all the employees are to be displayed excluding the management team.You have created a list named employees which contains 200 employee names. The first 10 employee names are of the management team in the list. You need to slice the employees list to display all employee names excluding the management team.Which code segments will you use to accomplish the task?Each correct answer represents a complete solution. Choose two. A employees[:10] B employees[10:] C employees[-190:] D employees[:-190]

employees[10:] employees[-190:]

Roy works as a HR in a company. He wants the details of all the employees present in the company. He has been provided with a file named employee.txt by a Python programmer which contains the details of all the employees. Roy has opened the file with the following Python code: file = open('employee.txt','r') Now, after opening the file, which of the following line of code should Roy use to see the details of all the employees?

file.read()

Oscar is a Python programmer. He has been asked to write a code in such a way that the code always executes whether an exception has occurred in it or not. Which of the following statements will Oscar use for this purpose? A try B continue C except D finally

finally

Peter is a Python developer in the ABC company. He has great skills in Python programming. He has been writing a program that includes extended slices. He has written the following code: s = 'Programming' print(s[3::]) print(s[::-1]) print(s[1:10:2]) print(s[:-1:1]) What will Peter get as the output for the given code?

gramming gnimmargorP rgamn Programmin

You are a Python programmer in an inventory company. You are asked to write a program to automate inventory. Your first task is to read a file named inventory.txt which contains the item id, price, and quantity from the previous day. The following is the data from the file: 100, 200, 5 20, 100, 1 Now, the program must meet the following requirements:Each line of the file must be read and printed.If a blank line is encountered, it must be ignored.When all lines have been read, the file must be closed.Based on the given list, you create the following code: inventory = open("inventory.txt", 'r') eof = False while eof == False: line = inventory.readline() # put the lines of code here print(line) else: print("End of file") eof = True inventory.close() Which of the following lines of code will you use?

if line != '\n': if line != "":

Dev is a Python programmer. He asked to write a program to get the instructor details of an institute. He has written the following code: def ins_details(ID, name="Will", age=30, subject="Java"): print("Name of the instructor is", name) print("Identity number of the instructor is", ID) print("Age of the instructor is", age) print("Subject taught by the instructor is", subject) Now, he has to call the function ins_details and then print the details. Which of the following ways of calling functions should not be used for the proper execution of the code?

ins_details(50, name='Jim', project="ABC")

Ray works as a Python developer in ABC company. He is developing a complex application in which he has to store an object in a file and then get it back later when needed. Which two standard modules will Ray use? A json B filecmp C copy D pickle

json pickle

Consider the following Python code: s = 'programming' for i in s: if i == 'm': continue print(i) What will be the output of the given code?

p r o g r a i n g

Samuel, a Python programmer, has written a code to print the following content of a file named file.txt: Python is interpreted programming language. Now, he was asked to not print the entire content of the file and just print the following part: Python is interpreted Which of the following methods will Samuel use to print the desired output?

read(21)

Dev is a beginner in the Python language. He has learned about the bitwise operator and has decided to check his knowledge. He has the following code: x = 12 y = 5 # Write the code here print(result) He wants the output as 12, which is the value of the result variable. Which line of code will Dev use for the desired result?

result = (x | y & ~y)

Tony, a user of a Python program, has written a line of code where the string s is used with spaces as follows: s = ' Python is an object-oriented programming language ' He wants to remove these extra spaces. Which of the following methods will be used for this purpose?

strip()

Rob is a Python developer in WER company. He has written the following code based on datetime module in which he wants to print the date in the format shown below: from datetime import date today = date.today() # put the line of code here 'Monday 15 October 2018' Which of the following will Rob use for the desired output? The output format always remains same but the date can vary according to the present date.

today.strftime("%A %d %B %Y")

David is an intern in the coding team of the ABC company. He is working on the Python language to create a commercial application. He has to create a script that asks a user for a value that is always used as a whole number even if the user enters a decimal value. Which code segment should David use?

value = int(float(input("Enter the value:")))

You are a Python instructor at the ABC institute. You have to test the knowledge of your students about the precedence of the operators and expressions in Python. You have provided the following code to them and asked a question based on it: def func(v, w, x, y, z): value = v + w * x - y / z return value Which part of the expression will be evaluated first?

w * x

John, an HR executive of the WER company, has to create a holiday calendar for the year 2018. He needs to calculate the number of days for the year and then add holidays. Thus, initially, he needs to check whether the year 2018 is a leap year. He has written the following code: year = int(input("Enter a year: ")) Enter a year: 2018 if (year % 4) == 0: if (year % 100) == 0: if (year % 400) == 0: print("{0} is a leap year", format(year)) else: print("{0} is not a leap year", format(year)) else: print("{0} is a leap year", format(year)) else: print("{0} is not a leap year", format(year)) The code has some issue, thus not giving the proper output. Which incorrect output will John get from the code?

{0} is not a leap year 2018


Conjuntos de estudio relacionados

THEORY EXAM #1 Practice Questions to Work On

View Set

Ch. 25 Cardiac, Ch. 26 Cardiac, Ch. 27 Cardiac, Ch 28. Cardiac

View Set

LoM Chapter 17 Dictaiton Ear-finale

View Set

B.4 CompTIA Network+ N10-008 Certification Practice Exam

View Set

Biology 1301 Final Exam-Connect Quiz

View Set

Health Assessment Ch. 13 Eye Assessment (Prep U)

View Set

hazmat #2, Hazardous material response!!!!!!!

View Set

comparison b/t ich gcp e6 and us fda regulations

View Set

Prepu Ch.53, 54 KIDNEY (Medsurg book)

View Set