0% found this document useful (0 votes)
89 views

Exam Dump

The document contains questions about Python programming concepts like data types, functions, control flow and more. It tests knowledge of expected output or behavior from code snippets.

Uploaded by

Heni Urip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
89 views

Exam Dump

The document contains questions about Python programming concepts like data types, functions, control flow and more. It tests knowledge of expected output or behavior from code snippets.

Uploaded by

Heni Urip
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

What is the expected output of the following code?

A. 21
B. 12
C. 3
D. none
A method for passing the arguments used by the following snippet is called:

A. sequential
B. named
C. positional
D. keyword
What is the expected behavior of the following code?

It will –
A. print 2 1
B. print 1 2
C. cause a runtime exception
D. print <generator object f at (some hex digits)>
What is the expected output of the following code?

A. 2
B. The code will cause a runtime exception
C. 1
D. 3
What is the expected behavior of the following code?

It will:
A. print 0
B. cause a runtime exception
C. prints 3
D. print an empty line
If any of a classes components has a name that starts with two underscores (___), then:
A. the class components name will be mangled
B. the class component has to be an instance variable
C. the class component has to be a class variable
D. the class component has to be a method
If you need to serve two different exceptions called Ex1 and Ex2 in one except branch, you can write:
A. except Ex1 Ex2:
B. except (ex1, Ex2):
C. except Ex1, Ex2:
D. except Ex1+Ex2:
A function called issubclass (c1, c2) is able to check if:
A. c1 and c2 are both subclasses of the same superclass
B. c2 is a subclass of c1
C. c1 is a subclass of c2
D. c1 and c2 are not subclasses of the same superclass
A class constructor (Choose two.)
A. can return a value
B. cannot be invoked directly from inside the class
C. can be invoked directly from any of the subclasses
D. can be invoked directly from any of the superclasses
The following class definition is given. We want the show () method to invoke the get ()
method, and then output the value the get () method returns. Which of the invocations
should be used instead of XXX?

A. print (get(self))
B. print (self.get())
C. print (get())
D. print (self.get (val))
f S is a stream open for reading, what do you expect from the following invocation?

A. one line of the file will be read and stored in the string called C
B. the whole file content will be read and stored in the string called C
C. one character will be read and stored in the string called C
D. one disk sector (512 bytes) will be read and stored in the string called C
You are going to read 16 bytes from a binary file into a bytearray called data. Which lines would you
use? (Choose two.)
A. data = bytearray (16) bf.readinto (data)
B. data = binfile.read (bytearray (16))
C. bf. readinto (data = bytearray (16))
D. data = bytearray (binfile.read (16))
What is the expected output of the following snippet?

A. True False
B. True True
C. False False
D. False True
Assuming that the code below has been executed successfully, which of the following
expressions will always evaluate to True? (Choose two.)

A. v1 >= 1
B. v1 == v2
C. len(random.sample([1,2,3],2)) > 2
D. random.choice([1,2,3]) >=1
Which one of the platform module functions should be used to determine the underlying
platform name?
A. platform.python_version()
B. platform.processor()
C. platform.platform()
D. platform.uname()
What will be the value of the i variable when the while e loop finishes its execution?

A. 1
B. 0
C. 2
D. the variable becomes unavailable
And operator able to perform bitwise shifts is coded as (Choose two.)
A. --
B. ++
C. <<
D. >>
What will the value of the i variable be when the following loop finishes its execution?

A. 10
B. the variable becomes unavailable
C. 11
D. 9
The following expression -
1+2
is:
A. equal to 1
B. invalid
C. equal to 2
D. equal to -1
A compiler is a program designed to (Choose two.)
A. rearrange the source code to make it clearer
B. check the source code in order to see of its correct
C. execute the source code
D. translate the source code into machine code
What is the output of the following piece of code?

A. ant‫ג‬€™ bat‫ג‬€™ camel


B. ant”bat”camel
C. antbatcamel
D. print (a, b, c, sep= ‫ ג‬€‫˜ ג‬€‫ג‬€™)
What is the expected output of the following snippet?

A. the code is erroneous


B. 3
C. 7
D. 15
How many lines does the following snippet output?

A. three
B. one
C. two
D. four
Which of the following literals reflect the value given as 34.23? (Choose two.)
A. .3423e2
B. 3423e-2
C. .3423e-2
D. 3423e2
What is the expected output of the following snippet?

A. 3
B. 1
C. 2
D. the code is erroneous
Assuming that the following snippet has been successfully executed, which of the equations
are True? (Choose two.)

A. len(a) == len (b)


B. b [0] +1 ==a [0]
C. a [0] == b [0]
D. a [0] + 1 ==b [0]
Assuming that the following snippet has been successfully executed, which of the equations
are False? (Choose two.)

A. len(a)== len (b)


B. a [0]-1 ==b [0]
C. a [0]== b [0]
D. b [0] - 1 ==a [0]
Which of the following statements are true? (Choose two.)
A. Python strings are actually lists
B. Python strings can be concatenated
C. Python strings can be sliced like lists
D. Python strings are mutable
Which of the following sentences are true? (Choose two.)
A. Lists may not be stored inside tuples
B. Tuples may be stored inside lists
C. Tuples may not be stored inside tuples
D. Lists may be stored inside lists
Assuming that String is six or more letters long, the following slice

is shorter than the original string by:


A. four chars
B. three chars
C. one char
D. two chars
What is the expected output of the following snippet?

A. 1
B. 4
C. 2
D. 3
What is the expected output of the following snippet?
A. abc
B. The code will cause a runtime exception
C. ABC
D. 123
How many elements will the list2 list contain after execution of the following snippet?

A. zero
B. five
C. seven
D. three
What would you used instead of XXX if you want to check weather a certain ‫ג‬€˜key‫ג‬€™ exists
in a dictionary called dict? (Choose two.)

A. ‫ג‬€˜key‫ג‬€™ in dict
B. dict [‫ג‬€˜key‫ג‬€™] != None
C. dict.exists (‫ג‬€˜key‫ג‬€™)
D. ‫ג‬€˜key‫ג‬€™ in dict.keys ( )
You need data which can act as a simple telephone directory. You can obtain it with the
following clauses (Choose two.) (assume that no other items have been created before)
A. dir={‫ג‬€˜Mom‫ ג‬,5551234567 :™€‫ג‬€˜Dad5557654321 :™€‫}ג‬
B. dir= {‫ג‬€˜Mom‫ ג‬,™€‫ג‬5551234567˜€‫ ג‬:™€‫ג‬€˜Dad‫ג‬5557654321 ˜€‫ ג‬:™€‫ג‬€™}
C. dir= {Mom: 5551234567, Dad: 5557654321}
D. dir= {Mom: ‫ג‬5551234567 ˜€‫ג‬€™, Dad: ‫ג‬5557654321 ˜€‫ג‬€™}
Can a module run like regular code?
A. yes, and it can differentiate its behavior between the regular launch and import
B. it depends on the Python version
C. yes, but in cannot differentiate its behavior between the regular launch and import
D. no, it is not possible; a module can be imported, not run
Select the valid fun () invocations:
(Choose two.)

A. fun (b=1)
B. fun (a=0)
C. fun (b=1, 0)
D. fun (1)
A file name like this one below says that:
(Choose three.)
services, cpython 36.pyc
A. the interpreter used to generate the file is version 3.6
B. it has been produced by CPython
C. it is the 36 version of the file
D. the file comes from the services.py source file
What is the expected behavior of the following snippet?

It will:
A. cause a runtime exception
B. print 1
C. print 0, [1]
D. print [1]
What can you do if you don‫ג‬€™t like a long package path like this one?

A. you can make an alias for the name using the alias keyword
B. nothing, you need to come to terms with it
C. you can shorten it to alpha . zeta and Python will find the proper connection
D. you can make an alias for the name using the as keyword
What is the expected output of the following code?

A. abcef
B. The program will cause a runtime exception/error
C. acdef
D. abdef
What is the expected output of the following code?

A. 21
B. 2
C. 3
D. 12
What is the expected behavior of the following snippet?
It will:
A. cause a runtime exception on line 02
B. cause a runtime exception on line 01
C. cause a runtime exception on line 03
D. print 3
What is the expected behavior of the following code?

It will:
A. print 4321
B. print <generator object f at (some hex digits)>
C. cause a runtime exception
D. print 1234
If you need a function that does nothing, what would you use instead of XXX? (Choose two.)

A. pass
B. return
C. exit
D. None

Python
1. You are writing a Python program to validate employee numbers. The employee number must
have the format ddd-dd-dddd and consist only of numbers and dashes. The program must print True
if the format is correct and print if the format is incorrect.
False -
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
2. You are coding a math utility by using Python.
You are writing a function to compute roots.
The function must meet the following requirements:

How should you complete the code? To answer, select the appropriate code segments in the answer
area.

3. You work for a company that distributes media for all ages.
You are writing a function that assigns a rating based on a user"™s age. The function must meet the
following requirements:
-> Anyone 18 years old or older receives a rating of "A"
-> Anyone 13 or older, but younger than 18, receives a rating of "T"
-> Anyone 12 years old or younger receives a rating of "C"
-> If the age is unknown, the rating is set to "C"
You need to complete the code to meet the requirements.
4. You are designing a decision structure to convert a student"™s numeric grade to a letter grade.
The program must assign a letter grade as specified in the following table:

For example, if the user enters a 90, the output should be, "Your letter grade is A". Likewise, if a user
enters an 89, the output should be "Your letter grade is B".
How should you complete the code? To answer, select the appropriate code segments in the answer
area.
5. You are developing a Python application for an online product distribution company.
You need the program to iterate through a list of products and escape when a target product ID is
found. How should you complete the code? To answer, select the appropriate code segments in the
answer area.

6. You are building a Python program that displays all of the prime numbers from 2 to 100. How
should you complete the code? To answer, drag the appropriate code segments to the correct
location. Each code segment may be used once, more than once, or not at all. You may need to drag
the split bar between panes or scroll to view content.

7. You are creating a Python script to evaluate input and check for upper and lower case.
Which four code segments should you use to develop the solution? To answer, move the
appropriate code segment from the list of code segments to the answer area and arrange them in
the correct order.

8. You develop a Python application for your company.


You have the following code. Line numbers are included for reference only.
9. The ABC company has hired you as an intern on the coding team that creates e-commerce
applications. You must write a script that asks the user for a value. The value must be used as a
whole number in a calculation, even if the user enters a decimal value. You need to write the code to
meet the requirements. Which code segment should you use?
A. totalItems = input("How many items would you like?")
B. totalItems = float(input("How many items would you like?"))
C. totalItems = str(input("How many items would you like?"))
D. totalItems = int(input("How many items would you like?"))

10. You create the following program to locate a conference room and display the room name. Line
numbers are included for reference only.

11. During school holidays, you volunteer to explain some basic programming concepts to younger
siblings. You want to introduce the concept of data types in Python. You create the following three
code segments:
12. Match the data type to the type operations. To answer, drag the appropriate data type to the
correct type operation. Each data type may be used once, more than once, or not at all.
Select and Place:

13. The ABC company needs a way to find the count of particular letters in their publications to
ensure that there is a good balance. It seems that there have been complaints about overuse of the
letter e. You need to create a function to meet the requirements. How should you complete this
code? To answer, select the appropriate code segments in the answer area.
14. The ABC Video company needs a way to determine the cost that a customer will pay for renting a
DVD. The cost is dependent on the time of day the DVD is returned. However, there are also special
rates on Thursdays and Sundays. The fee structure is shown in the following list:
-> The cost is $1.59 per night.
-> If the DVD is returned after 8 PM, the customer will be charged an extra day.
-> If the video is rented on a Sunday, the customer gets 30% off for as long as they keep the video.
-> If the video is rented on a Thursday, the customer gets 50% off for as long as they keep the video.
You need to write code to meet the requirements.
How should you complete the code? To answer, select the appropriate code segments in the answer
area.

15. The ABC company is converting an existing application to Python. You are creating
documentation that will be used by several interns who are working on the team. You need to
ensure that arithmetic expressions are coded correctly. What is the correct order of operations for
the six classes of operations ordered from first to last in order of precedence? To answer, move all
operations from the list of operations to the answer area and arrange them in the correct order.
16. You are writing a Python program. The program collects customer data and stores it in a
database.
The program handles a wide variety of data. You need to ensure that the program handles the data
correctly so that it can be stored in the database correctly. Match the data type to the code
segment. To answer, drag the appropriate data type from the column on the left to its code segment
on the right. Each data type may be used once, more than once, or not at all.

17. You are creating a Python program that shows a congratulation message to employees on their
service anniversary. You need to calculate the number of years of service and print a congratulatory
message. You have written the following code. Line numbers are included for reference only.

You need to complete the program. Which code should you use at line 03?
A. print("Congratulations on" + (int(end)-int(start)) + "years of service!")
B. print("Congratulations on" + str(int(end)-int(start)) + "years of service!")
C. print("Congratulations on" + int(end - start) + "years of service!")
D. print("Congratulations on" + str(end - start)) + "years of service!")

18. You are developing a Python application for your company.


You write the following code:
19. You are writing a Python program to perform arithmetic operations.
You create the following code:

20. You are writing a Python program that evaluates an arithmetic formula.
The formula is described as b equals a multiplied by negative one, then raised to the second power,
where a is the value that will be input and b is the result.
You create the following code segment. Line numbers are included for reference only.

You need to ensure that the result is correct.


How should you complete the code on line 02? To answer, drag the appropriate code segment to
the correct location. Each code segment may be used once, more than once, or not at all. You may
need to drag the split bar between panes or scroll to view content.
NOTE: Each correct selection is worth one point.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy