COP3035 Final

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

Given: for i in range(1, 10): print(i) Which one of the following is the correct implementation using "while" loop for the above? Please circle. a) i=1 while (i < 10) print(i) i=i+ b) i=1 while (i <= 10) print(i) i=i+1

A

Which are the numeric data types in python? a. int b. float c. string d. list

A.int b. float

Which one of these is a Fibonacci series? a. 1,2,5,6,7,8 b. 1,2,3,5,8,11 c. 1,2,3,4,5,6 d. None of the above

B

Which one of these provide a set of recommendations about how to write readable Python programs? a. PPP b. PEP8 c. Jython d. None of the above

B. PEP8

Suppose list1 is [2, 33, 222, 14, 25], What is list1[-1]? a) Error b) None c) 25 d) 2

C 25

Which one of the following numeric data types does not support typical numeric operations? a. int b. float c. complex d. long

C. complex

Suppose list1 is [4, 2, 2, 4, 5, 2, 1, 0], Which of the following is correct syntax for slicing operation? a) print(list1[0]) b) print(list1[:2]) c) print(list1[:-2]) d) all of the mentioned

D

t/f Arguments with default values can appear at the start of the arguments list of a function?

FALSE

t/f Both mutable and immutable objects can be changed in the called function in python?

FALSE

t/f What will the following produce? >>> 1.1 * 3.0 == 3.3

False (HINT: 3.3000000000000003)

T/f Multi-line comments begin and end with three #s in python?

False (HINT: Use """ comments """).

T/f In python 3, the statement - print "Hello, World!" - will run without any error?

False hint: use print("Hello World!"))

t/f If a module is executed directly, the value of the global variable __name__ will be "__main__"?

TRUE

t/f In turtle programming, turning 30 to the left will leave you facing in the same direction as turning 330 to the right?

TRUE

t/f Is a list mutable in python?

True

Suppose listExample is ['h','e','l','l','o'], what is len(listExample)? a) 5 b) 4 c) None d) Error

a) 5

What is the result when we execute list("hello")? a) ['h', 'e', 'l', 'l', 'o']. b) ['hello']. c) ['llo']. d) ['olleh'].

a) ['h', 'e', 'l', 'l', 'o'].

Suppose list1 is [2, 33, 222, 14, 25], What is list1[:-1] ? a) [2, 33, 222, 14]. b) Error c) 25 d) [25, 14, 222, 33, 2].

a) [2, 33, 222, 14].

Circle the functions that are used for creating a range of integers? a) range() b) xrange() c) prange() d) mrange()

a) range() b) xrange()

If d is a valid dictionary, then circle the valid operations? a)d.keys() b) d.values() c) d.items() d) d.reverse()

a)d.keys() b) d.values() c) d.items()

Which of the following is immutable? a. string b. list c. dictionary d. set

a. string

which are the sequence data types in python? a. string b. list c. tuple d. dictionary

a. string b. list c. tuple

Which of the following is a Python tuple? a) [1, 2, 3] b) (1, 2, 3) c) {1, 2, 3} d) {}

b) (1, 2, 3)

What would be the output of int(6.3)? a) 5 b) 6 c) 7 d) 8

b) 6

Circle the true statements for python? a) Python supports strong typing b) Python supports dynamic typing c) 2+"six" will not give any error

b) Python supports dynamic typing

What is the output of the following code? Class Demo: ...def __init__(self): ........pass ...def test(self): ..........print(__name__) obj =Demo() obj.test() a) Exception is thrown b) __main__ c) Demo d) test

b) __main__

The readlines() method returns a) str b) a list of lines c) a list of single characters d) a list of integers

b) a list of lines

If a={5,6,7}, what happens when a.add(5) is executed? a) a={5,5,6,7} b) a={5,6,7} c) Error as there is no add function for set data type d) Error as 5 already exists in the set

b) a={5,6,7}

What does alex.forward(-100) mean in Turtle Programming when you want the turtle "Alex" to be moved? a) alex moves forward by 100 units b) alex moves backward by 100 units c) alex turn left by 100 degree d) alex turn right by 100 degree

b) alex moves backward by 100 units

Which of the following will make alex to go at slowest speed? a) alex.speed(0) b) alex.speed(1) c) alex.speed(10)

b) alex.speed(1)

To open a file c:\scores.txt for reading, we use a) infile = open("c:\scores.txt", "r") b) infile = open("c:\\scores.txt", "r") c) infile = open(file = "c:\scores.txt", "r") d) infile=open(file = "c:\\scores.txt","r")

b) infile = open("c:\\scores.txt", "r")

Suppose d = {"john":40, "peter":45}. To obtain the number of entries in dictionary which command do we use? a) d.size() b) len(d) c) size(d) d) d.len()

b) len(d)

Suppose t = (1, 2, 4, 3), which of the following is incorrect? a) print(t[3]) b) t[3] = 45 c) print(max(t)) d) print(len(t))

b) t[3] = 45

What happens when '1' == 1 is executed? a) we get a True b) we get a False c) a TypeError occurs d) a ValueError occurs

b) we get a False

What would be the printed outputs for the following program? for i in range(20,14,-2): print i a) 18,19,20 b) 20,19,18,17 c) 20,18,16 d) 20,18,16,14

c) 20,18,16

What is the output of the following code? nums = set([1,1,2,3,3,3,4,4]) print(len(nums)) a) 7 b) Error, invalid syntax for formation of set c) 4 d) 8

c) 4 sets dont have duplicates

Suppose d = {"john":40, "peter":45}, what happens when we try to retrieve a value using the expression d["susan"]? a) Since "susan" is not a value in the set, Python raises a KeyError exception b) It is executed fine and no exception is raised, and it returns None c) Since "susan" is not a key in the set, Python raises a KeyError exception d) Since "susan" is not a key in the set, Python raises a syntax error

c) Since "susan" is not a key in the set, Python raises a KeyError exception

Suppose d = {"john":40, "peter":45}, to delete the entry for "john" what command do we use a) d.delete("john":40) b) d.delete("john") c) del d["john"]. d) del d("john":40)

c) del d["john"].

To read the next line of the file from a file object infile, we use a) infile.read(2) b) infile.read() c) infile.readline() d) infile.readlines()

c) infile.readline()

Which of the following turtle methods leaves an impression of the turtle methods? a) left b) right c) stamp d) shape

c) stamp

When will the else part of try-except-else be executed? a) always b) when an exception occurs c) when no exception occurs d) when an exception occurs in to except block

c) when no exception occurs

Which of the following statements create a dictionary? a) d = {} b) d = {"john":40, "peter":45} c) d = {40:"john", 45:"peter"} d) All of the mentioned

d) All of the mentioned

What is Instantiation in terms of OOP terminology? a) Deleting an instance of class b) Modifying an instance of class c) Copying an instance of class d) Creating an instance of class

d) Creating an instance of class

Which of these about a set is not true? a) Mutable data type b) Allows duplicate values c) Data type with unordered values d) Immutable data type

d) Immutable data type

If a={5,6,7,8}, which of the following statements is false? a) print(len(a)) b) print(min(a)) c) a.remove(5) d) a[2]=45

d) a[2]=45

Which of the following commands will create a list? a) list1 = list() b) list1 = [ ] c) list1 = list([1, 2, 3]) d) all of the mentioned

d) all of the mentioned

Which of the following statements are true? a) When you open a file for reading, if the file does not exist, an error occurs b) When you open a file for writing, if the file does not exist, a new file is created c) When you open a file for writing, if the file exists, the existing file is overwritten with the new file d) all of the mentioned

d) all of the mentioned

When is the "finally" block executed? a) when there is no exception b) when there is an exception c) only if some condition that has been specified is satisfied d) always

d) always

what are the modes in which we can run python code?.

normal mode and interpreted mode


Conjuntos de estudio relacionados

Quiz Reviews from Chapter 5,6,7,8,10

View Set

Chapter 5 PrepU Questions - Cultural Diversity

View Set

Chapter 64: Care of Patients with Diabetes Mellitus

View Set

OWare- Earth And Space Science 4. Forces And Features Of Earth

View Set

Sleeps, Dreams and Disorders #5 : Dreams (Part 1)

View Set

Chapter 30: Assessment and Management of Patients With Vascular Disorders and Problems of Peripheral Circulation

View Set

Area and Perimeter of All Shapes

View Set