Python God Quiz

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

How do you insert COMMENTS in Python code? A: #like this B: /*like this*/ C: //like this

A: #like this

Which operator is used to multiply numbers? A: * B: # C: x D: %

A: *

Which of the following literals reflect the value given as 34.23? (Choose two.) A: .3423e2 B: 3423e-2 C: .3423e-2 D: 3423e2

A: .3423e2 B: 3423e-2

What is true about the __init__.py file? (Select all that apply) A: It is required to make Python treat a given directory as a Python package directory B: It can execute an initialization code for a package C: It cannot be an empty file D: It is required to make Python treat a given directory containing packages as a directory without packages

A: It is required to make Python treat a given directory as a Python package directory B: It can execute an initialization code for a package

Which collection is ordered, changeable, and allows duplicate members? A: List B: Dictionary C: Set D: Tuple

A: List

You develop a Python application for your company. You want to add notes to your code so other team members will understand it. What should you do? A: Place the notes after the # sign on any line B: Place the notes after the last line of code separated by a blank line C: Place the notes before the first line of code separated by a blank line D: Place the notes inside of parentheses on any time E: Place the notes inside of commas on any time

A: Place the notes after the # sign on any line

Which collection does not allow duplicate members? A: Set B: List C: Tuple

A: Set

What can you deduce from the following statement? (Select two answers) str = open('file.txt', "rt") A: a new line character translation will be performed during the reads B: if file. txt does not exist, it will be created C: the opened file cannot be written with the use of the str variable D: str is a string read in from the file named file. txt

A: a new line character translation will be performed during the reads C: the opened file cannot be written with the use of the str variable

What is the correct way to create a function in Python? A: def function(): B: function function (): C: create function():

A: def function():

How do you start writing an if statement in Python? A: if x > y: B: if (x > y) C: if x > y then :

A: if x > y:

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

A: len(a) == len (b) C: a [0] == b [0]

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

A: len(a)== len (b) B: a [0]-1 ==b [0]

If you need a function that does nothing, what would you use instead of XXX? (Choose two.) def idler(): XXX A: pass B: return C: exit D: None

A: pass D: None

What is the correct file extension for Python files? A: print(type(x)) B: print(typeOf(x)) C: print(typeof x) D: print(typeof(x))

A: print(type(x))

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 D: the file comes from the services.py source file

A: the interpreter used to generate the file is version 3.6 B: it has been produced by CPython

Which method can be used to return a string in upper case letters? A: upper() B: toUpperCase() C: upperCase() D: uppercase()

A: upper()

How do you start writing a while loop in Python? A: while x > y: B: while (x > y) C: x > y while { D: while x > y {

A: while x > y:

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

A: yes, and it can differentiate its behavior between the regular launch and import

Which of these collections defines a SET? A: {"apple", "banana", "cherry"} B: ["apple", "banana", "cherry"] C: {"name": "apple", "color": "green"} D: ("apple", "banana", "cherry")

A: {"apple", "banana", "cherry"}

Which operator can be used to compare two values? A: <> B: == C: >< D: =

B: ==

How do you start writing a for loop in Python? A: for x > y: B: for each x in y: C: for x in y:

C: for x in y:

Select the true statements: (select all that apply) A: An object variable is a variable that is stored separately in every object B: A constructor is used to instantiate an object C: The class keyword marks the beginning of the class definition D: An object cannot contain any references to other objects E: A class may define an object

B: A constructor is used to instantiate an object C: The class keyword marks the beginning of the class definition

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

B: Python strings can be concatenated C: Python strings can be sliced like lists

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

B: Tuples may be stored inside lists D: Lists may be stored inside lists

What is the output of the following piece of code? a = 'ant' b = "bat" c = 'camel' print (a, b, c, sep= ' " ' A: ant bat camel B: ant"bat"camel C: antbatcamel D: print (a, b, c, sep= ג€˜ ג€ ג€™)

B: ant"bat"camel

A compiler is a program designed to (select two answers) A: rearrange the source code to make it clearer B: check the source code in order to see of it's correct C: execute the source code D: translate the source code into machine code

B: check the source code in order to see of it's correct D: translate the source code into machine code

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 itג€™s correct C: execute the source code D: translate the source code into machine code

B: check the source code in order to see of itג€™s correct D: translate the source code into machine code

You develop a Python application for your company. A list named employees contains 200 employee names, the last five being company management. You need to slice the list to display all employees excluding management. Which two code segments should you use? Each correct answer presents a complete solution. (Choose two.) A: employees [1:-4] B: employees [:-5] C: employees [1:-5] D: employees [0:-4] E: employees [0:-5]

B: employees [:-5] D: employees [0:-4]

In Python, 'Hello', is the same as "Hello" A: true B: false

B: false

Select the valid fun () invocations: (Choose two.) def fun (a, b=0) return a*b A: fun (b=1) B: fun (a=0) C: fun (b=1, 0) D: fun (1)

B: fun (a=0) D: fun (1)

You develop a Python application for your school. You need to read and write data to a text file. If the file does not exist, it must be created. If the file has content, the content must be removed. Which code should you use? A: open("local_data", "r") B: open("local_data", "w+") C: open("local_data", "r+") D: open("local_data", "w")

B: open("local_data", "w+")

What is a correct syntax to output "Hello World" in Python? A: p("Hello World") B: print("Hello World") C: echo "Hello World" D: echo("Hello World);

B: print("Hello World")

You are writing code that generates a random integer with a minimum value of 5 and a maximum value of 11. Which two functions should you use? Each correct answer presents a complete solution. (Choose two.) A: random.randint(5, 12) B: random.randint(5, 11) C: random.randrange(5, 12, 1 D: random.randrange(5, 11, 1

B: random.randint(5, 11) C: random.randrange(5, 12, 1

What will the value of the i variable be when the following loop finishes its execution: for i in range (10): pass A: 10 B: the variable becomes unavailable C: 11 D: 9

B: the variable becomes unavailable

Assuming that String is six or more letters long, the following slice string [1:-2] is shorter than the original string by: A: four chars B: three chars C: one char D: two chars

B: three chars

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

B: totalItems = float(input("How many items would you like?"))

What is a correct syntax to return the first character in a string? A: x = "Hello".sub(0, 1) B: x = "Hello"[0] C: x = sub("Hello", 0, 1

B: x = "Hello"[0]

You have the following code: v = bool([False]) x = bool(3) y = bool("") z = bool(' ') Which of the variables will equal False? A: z B: y C: x D: v

B: y

Which of these collections defines a DICTIONARY? A: {"apple", "banana", "cherry"} B: {"name": "apple", "color": "green"} C: ["apple", "banana", "cherry"] D: ("apple", "banana", "cherry")

B: {"name": "apple", "color": "green"}

What is the correct file extension for Python files? A: .pyth B: .pyt C: .py D: .pt

C: .py

What is the expected output of the following snippet? lst =[1,2,3,4] lst = lst [-3:-2] lst = lst [-1] print(lst) A: 1 B: 4 C: 2 D: 3

C: 2

And operator able to perform bitwise shifts is coded as (Choose two.) A: -- B: ++ C: << D: >>

C: << D: >>

Which of these collections defines a LIST? A: {"name": "apple", "color": "green"} B: {"apple", "banana", "cherry"} C: ["apple", "banana", "cherry"] D: ("apple", "banana", "cherry")

C: ["apple", "banana", "cherry"]

Which statement is used to stop a loop? A: return B: exit C: break D: stop

C: break

You are writing an application that uses the sqrt function. The program must reference the function using the name squareRoot. You need to import the function. Which code segment should you use? A: import math.sqrt as squareRoot B: import sqrt from math as squareRoot C: from math import sqrt as squareRoot D: from math.sqrt as squareRoot

C: from math import sqrt as squareRoot

How many elements will the list2 list contain after execution of the following snippet? list1 = [False for i in range(1,10)] list2 = list1 [-1:1:-1] A: zero B: five C: seven D: three

C: seven

Which method can be used to remove any whitespace from both the beginning and the end of a string? A: ptrim() B: trim() C: strip() D: len()

C: strip()

Which of these collections defines a TUPLE? A: {"apple", "banana", "cherry"} B: {"name": "apple", "color": "green"} C: ["apple", "banana", "cherry"] D: ("apple", "banana", "cherry")

D: ("apple", "banana", "cherry")

You run the following code: def calc1(rate, item): item *= (1 + rate) rate = 0.25 item = 12000 calc1(rate, item) print('Rate:', rate, '; Value:', item) What will be displayed on the screen? A: Rate: 1.25 ; Value: 15000 B: Rate: 1.25 ; Value: 12000 C: Rate: 0.25 ; Value: 15000 D: Rate: 0.25 ; Value: 12000

D: Rate: 0.25 ; Value: 12000

You are going to read just one character from a stream called s. Which statement would you use? A: ch = input(s, 1) B: ch = s.input(1) C: ch = read(s, 1) D: ch = s.read (1)

D: ch = s.read (1)

The following expression - 1+-2 is: A: equal to 1 B: invalid C: equal to 2 D: equal to -1

D: equal to -1

How many elements will the list2 list contain after execution of the following snippet? List1= [False for i in range(1,10)] list2 = list1[-1:1:-1] A: zero B: three C: seven D: five

D: five

Which one is NOT a legal variable name? A: Myvar B: my_var C: _myvar D: my-var

D: my-var

Which method can be used to replace parts of a string? A: repl() B: switch() C: replaceString() D: replace()

D: replace()

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

D: totalItems = int(input("How many items would you like?"))


Set pelajaran terkait

Dual Agency and Transaction Brokerage

View Set

Unit 5 Chapter 12 Gross Domestic product and growth

View Set

PARALLELOGRAMS: RECTANGLES AND RHOMBUSES

View Set

Managerial Accounting Chapter 3: ABC

View Set

Market segmentation - (Target markets & segmentation)

View Set

CITI Responsible Conduct of Research (RCR) - Basic

View Set