Functions
loops
lists
misc
100
The keyword to create a function

What is “def”

100

Loop that runs a predetermined number of times

What is for loop

100

Function to get the length of a list or a string

What is len

100

Comment line starts with this character 

What is #

200

Function to display a string on screen

What is print

200

loop that runs as long as the condition is true

What is while loop

200

This type of bracket defined a list

What is square brackets []

200

The following will print a line showing the number 4:

for i in range(4):
    print(i)

What is false

300

Function to convert a number to a string 

What is str

300

Keyword to get out of a loop

What is break

300

The index of the first element of a list

What is 0

300

Which of the following operators is used for equality comparison in Python?

  • A

    ==

  • B

    =

  • C

     ===

  • D

    >

What is A

400

Function to convert a string to a number

What is int

400

The number of lines that will be printed

for number in [10, 9, 8, 7, 6, 5, 4, 3, 2, 1, 0]:

    print("I have", number, "cookies.  I'm going to eat one.")


What is 11

400

The index for the third element of a list 

What is 2

400

What is printed:

x = 5

if x > 0:

  print("Positive")

else:

  print("Negative")

What is Positive 

500

Which of the following correctly defines a function in Python?

  • A

    function add(a, b) return a + b

  • B

    def add(a, b): return a + b

  • C

    def add = (a, b) => a + b

  • D

    add(a, b) = def return a + b

What is B

500

The value that the last line print:

i = 1

while (i <= 3):
    i = i + 1
    print(i)

What is 4

500

fruits=[“apple”, “banana”, “grapes” , “oranges”]

print(fruits[3])

What is oranges

500

What is the output of the following code snippet?

for i in range(5):
   if i == 3:
       continue
   print(i)
 

  • A

     0 1 2 3 4

  • B

    0 1 2 4

  • C

    0 1 2

  • D

    0 1 2 3

What is B

M
e
n
u