what type of data can a variable hold? a: numbers b: strings c: a & b d: practically everything

Post on 26-Mar-2015

221 Views

Category:

Documents

0 Downloads

Preview:

Click to see full reader

TRANSCRIPT

What type of data can a variable hold?

• A: Numbers• B: Strings• C: A & B• D: Practically everything

Which of the following *is* a valid variable name?

A.ninety_nine_balloonsB.ninety nine balloonsC.99_balloons

Which of the following *IS NOT* a string?

A.“42”B.‘42’C.42

What would happen if you attempt to assign a value to a variable that does

not exist?

Example: some_variable = 235

A.Nothing happensB.“some_variable” now holds the value 235C.Python generates an error

What would happen if you attempt to PRINT a variable that does not exist?

Example: print(foo)

A.Nothing happensB.PRINT outputs and empty stringC.Python generates an error

What is the value of my_var after the following execution sequence?

>>> my_var = 0

>>> my_var = 7

>>> my_var = my_var + 1

A.7B.8C.0

Which of the following are control structures?

A. FORB. IFC. input()D. A & BE. A, B, & C

A comment in Python is indicated by a:

A.Colon (:)

B.Dollar sign ($)

C.Asterisk (*)

D.Pound Sign (#)

Which variable is properly named?

A.MyVariableB.myVariableC.my_variableD.My_VariableE.My Variable

What is the default data type of all user input?

A.int

B.string

C.float

D.main

How do we obtain user input?

A.input()

B.print()

C.FOR

D.float()

How many times will this loop?

for i in range(7):

pass

A.0

B.7

C.8

D.6

Ask the audience: Why do we use “pass” below?

for i in range(7):

pass

How much will the variable “i” equal at the end of the loop?

for i in range(8):

pass

A.0

B.6

C.7

D.8

E.9

What is the value of x after this loop?

x = 1for i in range(3): x = i * 2

A.0B.3C.6D.8E.4

What data type holds decimal numbers?

A.int

B.float

C.char

D.string

How many times will the PRINT get called?

for i in range(8): for j in range(7): print("hello")

A.0B.7C.8D.42E.56

Which of the following *IS NOT* a relational operator (used in IF

statements)

A.<

B.==

C.!=

D.=

E.>=

Which Checks Get Passed?x = 25if x == 25: print("passed 1st check")if x > 25: print("passed 2nd check")if x < 25: print("passed 3rd check")if x > 1: print("passed 4th check“)

Answer Check 1 Check 2 Check 3 Check 4

A Yes No No Yes

B Yes No No No

C No Yes No Yes

D Yes Yes Yes Yes

What data type holds whole numbers?

A.int

B.float

C.char

D.string

What is the output?

A = ‘this’B = “that”print(a + b)

A.Python throws an errorB.this thatC.‘this’”that”D.thisthat

What does x equal?

x = input(“Enter x: “)

(we enter: -2 * 3 + 5)

A.-16

B.-1

C.‘-2 * 3 + 5’

D.Python throws an error

What is the value of x after the following operation?

x = 10 // 3

A.0

B.3.333333333

C.3

D.1

What is the result?

4 * 1 // 2

A. 2

B. 0

C.2.0

D.2.5

What is the value of x after the following operation?

my_string = “I like lamp”

x = my_string[2]

A.I

B.L

C.K

D.like lamp

What is the output?

print(2 + 3)

A.2 + 3

B.2 + 3 = 5

C.5

D.Python throws an error

What Is the Output?numerator = 4denominator = 2if denominator == 0: print("Cannot divide by zero!")else: print( \ numerator, \ "/", \ denominator, \ "=", \ numerator / denominator \ )

A. Cannot divide by zero!B. 2.0

What Is the Output?guess = 35if guess < 100: if guess > 50: print("Do") elif guess > 25: print("Re") else: print("Mi")else: print("Fa")

A. DoB. ReC. MiD. Fa

What Is the Output?guess = 25if guess < 100: if guess > 50: print("Do") elif guess > 25: print("Re") else: print("Mi")else: print("Fa")

A. DoB. ReC. MiD. Fa

Quiz Question

The main difference between FOR and WHILE loops is that we usually know the exact number of iterations in a FOR loop.

A.True

B.False

Are these loops equivalent?

i = 0while i <= 9: print(i) i = i + 1----------------for i in range(11): print i

A.YesB.No

top related