Programming Study Guide 2

Ace your homework & exams now with Quizwiz!

Which of the following is a run-time error?

Attempting to divide by 0

Which of the following is the correct way to declare a tuple?

my_tuple = (15,)

Which of the following options is NOT a valid Python function definition? a. # computes the surface area of a cube of side length 10 # def surface_area(): return 2*(100 + 100 + 100)

# computes the surface area of a rectangular prism def surface_area(length, width=10, height): return 2*(length * width + width * height + height * length)

What result will be printed out after running the following program? current_time = input("What is the current time (in hours 0 - 23)?") wait_time = input("How many hours do you want to wait") print(current_time) print(wait_time) final_time = current_time + wait_time print(final_time)

. A combined string value between current_time and wait_time.This answer is correct.

What is printed by the following statements? alist = [4, 2, 8, 6, 5] alist = alist + 999 print(alist)

. Error, you cannot concatenate a list with an integer.

What is RGB stand for?

. Red green blue

In the following code, we define a variable and use it to draw a rectangle: var rectWidth = 20; rect(10, 10, rectWidth - 5, rectWidth - 5); How wide is the rectangle?

15

What is a list?

A collection of objects, where each object is identified by an index.

In Python a module is:

A file containing Python definitions and statements intended for use in other Python programs.

What is the difference between a tab ('\t') and a sequence of spaces?

A tab will line up items in a second column, regardless of how many characters were in the first column, while spaces will not.

What is printed by the following statements? myname = "Edgar Allan Poe" namelist = myname.split() init = "" for aname in namelist: init = init + aname[0] print(init)

EAP

A list can contain only integer items.

False

All standard Python modules will work in activecode.

False

What is printed by the following statements? alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False] print(57 in alist)

False

Which of the following is a syntax error?

Forgetting a colon at the end of a statement where one is required.

Which of the following is a semantic error?

Forgetting to divide by 100 when printing a percentage amount.

To find out information on the standard modules available with Python you should:

Go to the Python Documentation site.

What does this program print? temperature = 65 while temperature < 80: print "It's still a nice day" if temperature < 70: temperature = temperature + 5 else: temperature = temperature + 3 if temperature > 75: break

It's still a nice day It's still a nice day It's still a nice day

What is in and not in operator do?

Tests whether one string is contained inside another string.

Who or what typically finds syntax errors?

The compiler / interpreter.

What is the purpose of exceptions?

To indicate that something has gone wrong, and the program does not know how to continue

What is printed by the following statements? alist = [3, 67, "cat", [56, 57, "dog"], [ ], 3.14, False] print(alist[4:])

[ [ ], 3.14, False]

What is printed by the following statements? a = ['one', 'two', 'three'] del a[1] print(a)

['one', 'three']

What is printed by the following statements? alist = [4, 2, 8, 6, 5] temp = alist.pop(2) temp = alist.pop() print(alist)

[4, 2, 6]

What is printed by the following statements? alist = [4, 2, 8, 6, 5] alist.append("cat") print(alist)

[4, 2, 8, 6, 5, "cat"]

What is printed by the following statements? alist = [4, 2, 8, 6, 5] alist[2] = True print(alist)

[4, 2, True, 6, 5]

A program is:

a sequence of instructions that specifies how to perform a computation.

What would this program print? def mystery(num, pattern): result = "" for i in range(num): result = result + pattern return result print mystery(3, "<>")

b. <><><>

What module do you need to use in Python for image processing?

cImage

Which of the following for loops would print the following numbers? 0 1 2 3 4 5

for i in range(6): print i

What does the following program print?

look at number 2 on study guide 2

What is printed by the following statements?

look in 33 in study guide 2

What will the following code print if x = 3, y = 5, and z = 2

look number 21 on study guide 2

How many times is the word HELLO printed by the following statements?

look on 36 on study guide 2

Will the following code cause an error?

look on question 30 on study guide 2

What statement you can use to help you uncover what is happening in your code?

print

What is printed by the following statements?

rockrockrock

Which of the following while loops would continue to loop as long as num is in the range 3 to 12, exclusive?

while num < 12 and num > 3: # do something with num

After the following statements, what are the values of x and y?

x is 50 and y is 24

Is the following statement legal in a Python function (assuming x, y and z are defined to be numbers

yes


Related study sets

Chapter X: Human Resource Management

View Set

Grounding and Bonding Terms and Conditions

View Set

Chapter 9: Cognitive and Behavioral Strategies

View Set

2 - ¿Qué te gusta hacer cuando...?

View Set

Ch. 15: Continuing Developments in Psychology

View Set

Combo with Administrative Law and 5 others

View Set