Intro to Programming test Q2

Pataasin ang iyong marka sa homework at exams ngayon gamit ang Quizwiz!

One reason that lotteries don't use computers to generate random numbers is

a. Because computers don't really generate random numbers, they generate pseudo-random numbers

Who or what typically finds syntax errors?

a. The compiler / interpreter

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!"

Can you use the same name for a local variable as a global variable

b. Yes, but it is considered bad form.

Considering the function below, which of the following statements correctly invokes, or calls, this function (i.e., causes it to run)? Assume we already have a turtle named alex.

b. drawSquare(alex, 10)

Which of the following is not a logical operator in Python?

because

What is a local variable?

c. A temporary variable that is only used inside a function

Which of the following is the correct way to reference the value pi within the math module. Assume you have already imported the math module.

c. math.pi

Which of the following prints BCDE

c. my_string = "ABCDE" print(my_string[1:])

What will the following function return? def addEm(x, y, z): print(x + y + z)

none

What are the parameters of the following function? def drawSquare(t, sz): """Make turtle t draw a square of with side sz.""" for i in range(4): t.forward(sz) t.left(90)

t,sz

Which module would you most likely use if you were writing a function to simulate rolling dice?

the random module

In the following line of code: my_boolean = True and (10 / 0 == 0) Will the 10 / 0 == 0 operation be evaluated?

yes

An algorithm is: a

. A step by step list of instructions that if followed exactly will solve the problem under consideration.

Which of the following best describes the main purpose of comments?

. Comments describe your program so other people can read it more easily.

How many possible values are there for a boolean variable?

2

Consider the following code import turtle wn = turtle.Screen() alex = turtle.Turtle() alex.forward(150) alex.left(90) alex.forward(75) What does the line "import turtle" do?

It defines the module turtle which will allow you to create a Turtle object and draw with it.

What is a variable's scope?

The range of statements in the code where a variable can be accessed

What is one main purpose of a function?

To help the programmer organize programs into chunks that match how they think about the solution to the problem.

What is a function in Python?

a. A named sequence of statements.


Kaugnay na mga set ng pag-aaral

Macroeconomics Quizzes for Test 1

View Set

Framework and Financial Reporting

View Set

A33 CH6: QUIZ- INFECTION PREVENTION - MELBENZ

View Set