¡GoConqr estrena diseño! Cuéntanos qué te parece.

Apuntes

exams

John Ovalles Inglés 1 página

Contenido del apunte (1)

Página 1

Summer 2017 CPSC1301 Quiz 1-Key Value = 10 points

Your Name:___Key______. Your answers go in the following table.

Q1- Q2- Q3- Q4- Q5-

Q6- Q7- Q8- Q9- Q10-

1) What function do you use to read a string?

A. input("Enter a string")

B. eval(input("Enter a string"))

C. enter("Enter a string")

D. eval(enter("Enter a string"))

2) If you enter 1 2 3 in three separate lines, when you run this program, what will be displayed?

print("Enter three numbers: ")

number1 = int(input())

number2 = int(input())

number3 = int(input())

# Compute average

average = (number1 + number2 + number3) / 3

# Display result

print(average)

A. 1.0

B. 2.0

C. 3.0

D. 4.0

(1 + 2 + 3)/3 = 2.0

3) Which of the following is a valid identifier? (check all that apply)

A. $343

B. mile

C. 9X

D. 8+9

E. max_radius

Cannot begin with a digit. Special characters not allowed, except for _.

4) What will be displayed by the following code?

x = 1

x = 2 * x + 1

print(x)

A. 0

B. 1

C. 2

D. 3

E. 4

2*x is evaluated first. Yields 2, because x holds 1. We then add 1 to it to get 3.

5) What is the result of 45 // 4?

A. 10

B. 11

C. 11.25

D. 12

// is the floored division operator. We know that 45/4 equals 11.25, since / is the “normal” division

operator. The // operator does away with the decimal part of 11.25.

6) Which of the following expressions results in a value 1?

A. 2 % 1

B. 15 % 4

C. 25 % 5

D. 37 % 6

% is the mod operator. It returns the remainder of the division of its left operand by its right operand.

The remainder of dividing 37 by 6 is 1.

7) What is x after the following statements?

x = 1

y = 2

x *= y + 1

A. x is 1

B. x is 2

C. x is 3

D. x is 4

y+1 is evaluated first. It yields 3, because y equals 2. So the expression x *= y + 1 becomes equivalent

to x *= 3 which multiplies x by 3.

8) To add a value 1 to variable x, you write (check all that apply)

A. 1 + x = x

B. x += 1

C. x := 1

D. x = x + 1

E. x = 1 + x

1 + x = x is not syntactically correct, since only a variable's name can be placed in front of the

assignment symbol. The := operator is not a Python operator.

9) What is the type for object 5.6?

A. int

B. float

C. str

D. bool

float is the data type that holds decimals.

10) Which of the following is a valid identifier? (check all that apply)

A. import

B. mile1

C. MILE

D. (red)

E. "red"

import is a reserved keyword that allows python to access certain modules (like the turtle module and

the random module). It cannot be used as an identifier (i.e., as the name of a variable).

Special characters like ( and “ are not allowed in identifiers.

Información

Descripción
Apunte sobre exams, creado por John Ovalles el 01/08/2017.
Creado por
John Ovalles
Visitas
0
Valoración

Escríbenos

¿Sobre qué es tu mensaje?

¿Qué te parece el nuevo diseño?

¿Te gusta?