Computer Science II Final

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

How many lines will this program print? while False: print "hello"

0

What does the following program print? for i in range(2): for j in range(2): print i + j

0 1 1 2

How many lines will the program below print? var = 0 while True: print var var = var + 1 if var == 10: break

10

How many lines will the program below print? for i in range(2): for j in range(4): print "hello" for k in range(2): print "hello"

12

How many possible values are there for a boolean variable?

2 (True and False)

How many lines will the program below print? var = 7 while True: print var var = var - 1 if var == 5: break

3

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

4

What is len("hello")?

5

How many lines will the program below print? for i in range(3): for j in range(3): print "hello"

9

What is a for loop used for?

A for loop is for doing something a certain number of times

What is an overhang on a 3D print?

A slanted surface without support material under it

What is a boolean?

A variable that can only be true or false

What is a while loop used for?

A while loop is for doing something over and over until a condition is met

What is a "string"?

A word or sentence

What is a logical operator?

An operator that compares the values of two booleans

What is a comparison operator?

An operator that compares the values of two numbers

On Tinkercad, how can you raise or lower a shape?

By clicking and dragging the black triangle

On Tinkercad, how can I pan the camera from left to right?

By clicking in the scroll wheel and dragging or holding shift and right-clicking and dragging

On Tinkercad, how can you select more than one object at once?

By holding shift and clicking each object or clicking and dragging over all of the objects

On Tinkercad, how can you rotate the camera?

By right-clicking and dragging or using the observations cube

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

False (this says 100 does not equal 100)

What does this Python expressions evaluate to? 56 < 56

False (this says 56 is less than 56)

What does the command "len" do?

Gives the amount of characters in a string

If I declare a variable outside of a function, which namespace is it in?

Global namespace (this means we can use the variable in anywhere in the code)

What will the following program print? var = 10 if var > 0: print "Greater than 0" elif var > 5: print "Greater than 5" else: print "Less than 0"

Greater than 0 (if an if-elif-else statement, only one will run)

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

II and III

What does the command "try" do?

It checks for errors and jumps to the "except" block if there is one

What does the command "except" do?

It tells the computer what to do if there is an error in the "try" block

If my_string is "Spring Break", what is my_string[6]?

It's a space

What will the following program print? var = 5 if var < 10: print "Less than 10" if var < 8: print "Less than 8" if var < 6: print "Less than 6"

Less than 10 Less than 8 Less than 6 (with three different if statements, all of them can run)

Will this program print anything or not? if False: print "hello"

No. "if False" will never run.

In the program below, which variables are in the global namespace? x = 10 def add_nums(): y = 2 z = x + y print z

Only x. y and z are declared inside of the function, so they are not in the global namespace.

What does the command "return" do?

Returns a value from a function

What kind of file do I need to 3D print?

STL

What does it mean that strings in Python are "immutable"?

Strings in Python can be replaced, but not modified.

How many lines will the program below print? var = 5 while True: print var var = var - 1 if var == 0: continue

The program will print an infinite number of lines

How many lines will the program below print? var = 5 while True: print var var = var -1 if var == 0: continue

The program will print an infinite number of lines (continue skips back to the beginning of the loop)

What is infill on a 3D print?

The structure printed inside the model

How many parameters can we use in each function?

There is no limit

If my_string is "classroom", what is my_string[9]?

There will be an error

What does this Python expression evaluate to? 21 = 21

There will be an error (remember, we have to use two equal signs in a comparison)

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

This line will print infinitely

What does this Python expression evaluate to? 15 == 15

True (15 is equal to 15)

What does this Python expression evaluate to? 5 >= 5

True (this says 5 is greater than or equal to 5)

On Tinkercad, what does "grouping" do?

Turns many objects into one object

Which color is best for covering up flaws in 3D prints?

White

Which one of these allows you to create a string that is the result of putting two different strings together, side by side? a. + b. - c. * d. /

a. + (we can "add" strings together with the + sign)

If we use the condition "while True:" in our program, which keyword should we use to make sure we don't create an infinite loop?

break (this will immediately skip to the end of the loop)

Which of the following is not a comparison operator? a. <= b. != c. ? d. >

c. ? (all of the others can be used to compare numbers)

Which of these is NOT a valid value for a boolean variable? a. True b. False c. Yes d. These area all valid values

c. Yes (A boolean can only be True or False)

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

continue

Which of the following is not a logical operator in Python? a. and b. or c. not d. because

d. because (all of the others can be used to compare two booleans)

How could we write a function that returns the number 10?

def my_function(): return 10

How could we write a function that returns double the variable "number"?

def my_function(number): return number*2

How would we write a function called "print_hello" that prints the word hello?

def print_hello(): print "hello"

How would we write a function called "print_number" that takes a single parameter and prints it?

def print_number(x): print x

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

def print_sum():

How do we write a standard for loop?

for i in range(count): code

Assuming we have defined a boolean variable called "bool", how do we use this variable to print "bool is true!" only if bool is set equal to True?

if bool: print "bool is true!"

How would I write a condition that tells me to take an umbrella if I have plans (plans = True) AND it's raining (rain = True)?

if plans == True and rain == True: take umbrella (just as an example, you could also say either of these are not false (!= False))

How do we check if the variables "var1" and "var2" are equal in an if statement?

if var1 == var2: (remember, we have to use two equal signs in a comparison)

How would I write a condition that tells me to stay home if it's the weekend (weekday = False) OR it's a holiday (holiday = True)?

if weekday != True or holiday == True: stay home (just as an example, you could also say weekday is False (== False) or holiday is not false (!= False))

If my_string is "Monday", what is my_string[2]?

n

If my_string is "ABCDE", how can I print "ABCD"?

print my_string [:3]

If my_string is "ABCDE", how do I print E without using the number 5?

print my_string[-1]

If my_string is "ABCDE", how do I print A?

print my_string[0]

If my_string is "ABCDE", how can I print "CDE"?

print my_string[2:]

If we assume the variable "sign" contains the string "Happy day!", how do we make it say "Happy Birthday!"

print sign[:6] + "Birth" + sign[6:]

How would we pass the number 10 to the function "print_number()"?

print_number(10)

If my_string is "sunflower", what is my_string[-1]?

r

How would I round the variable "x" to two decimal places?

round(x, 2)


संबंधित स्टडी सेट्स

Microbiology Exam 4 -- Important Pathogens & Public Health

View Set

ICT IGCSE Topic 1 - Types and components of a computer system

View Set

CISSP Cert Guide Chapter 6. Security Assessment and Testing Quiz

View Set