Intermediate Programming

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

How many lines will this program print? while True: print "hi"

infinite

What code correctly passes the number 10 as an argument to the function print_number?

print_number(10)

What type is the following variable? x = "Hi there"

string

Assume you are writing a program, and you have a boolean variable called b, defined like so: b = True Pick the correct if statement to follow the code above. The if statement should be correct Python, and the body of the if statement should only run if b is True. A) if b: print "b is True!" B) if b: print "b is True!" C) if True: print b D) if True: print b

A

What does the following program print? for i in range(2): for j in range(2): print i + j A) 0 1 1 2 B) 0112 C) 0 1 0 1 D) 0101

A

Which of the following functions successfully returns double the variable 'number'? A) def my_function(number): return number*2 B) def my_function(number*2): return C) def my_function(): return number D) def my_function(number): number*2

A

Which of the following is NOT a valid type of comment in Python? A) %% This is a comment B) # This is a comment C) """ This is a comment

A

Which of the following operations will output a value of 5? A) 11/2 B) 11.0/2 C) float(11)/2 D) 2 + 3 * 2

A

Which of the following programs prints ten lines? A) for i in range(10): print "hi" B) for i = 1 to 10: print "hi" C) for i in 1 - 10: print "hi" D) for i from 0 to 9: print "hi"

A

Which of the following best describes the main purpose of comments? A) Comments create better spacing in programs. B) Comments describe your program so other people can read it more easily. C) Comments warn the people running the program about potential problems with the program.

B

Which of the following programs will not print anything? A) x = True if x: print "hi" B) if False: print "hi" C) x = False if x: print "hi" else: print "hello"

B

Which of the following best describes the purpose of a for loop? A) A for loop is for doing something an indeterminate number of times. B) A for loop is doing something an infinite number of times. C) A for loop is for doing something a fixed number of times. D) A for loop is for doing something three times.

C

Which of the following is not a comparison operator? A) <= B) != C) ? D) >

C

Which of the following is not a logical operator in Python? A) and B) or C) not D) because

D

Which of the following is the correct way to declare a function in Python? A) print_hello: print "hello" B) function print_hello(): print "hello" C) print_hello(): print "hello" D) def print_hello(): print "hello"

D

What does this Python expression evaluate to? 100 != 100

False

Which of the following keywords are relevant to exceptions in Python? I. def II. except III. try

II and III

If I am using the following condition in my program: while True: which keyword should I use to make sure I don't create an infinite loop?

break

Which Python keyword skips back to the beginning of a loop?

continue

In which namespace is the variable 'x' defined in the following program? x = 10 def add_nums(): y = 2 z = x + y print z

global namespace

How do you display "Hello, world!" on the screen?

print "Hello, world!"

What is the correct way to call a function named 'print_sum'?

print_sum()

What code evaluates to the variable x rounded to two decimal places?

round(x, 2)

What is the type of the variable x in the following Python program? x = input("Enter something: ")

string

What does the following Python program print? x = 9 + 6 / 3 * 2 - 1 print x

12

How many lines will this program print? x = 10 while x > 0: print x x = x - 3

4


Set pelajaran terkait

ITEC 1001- Networking and Immersive Technology

View Set

Financial Accounting Ch. 4, 5, 6

View Set

Intercultural Communication Prelim

View Set

Ch. 3 Sequences, Sums, and Inductions

View Set

Relias- Overview of Medicaid and Medicare

View Set