Lists
Tuples
Functions
Loops
Mixed
100

What method would you use to add an item to the end of a list?

append()

100

What is a tuple in Python?

immutable sequence of items

100

What keyword is used to define a function in Python?

def

100

Write a simple for loop that prints numbers from 1 to 5.

for x in range (1,6):

    print (x)

100

Which data type is used to store multiple items in a single variable?

list or tuple

200

What function would you use to find the largest number in a list?

max()

200

How do you create a tuple with one item?

tuple_name = (item,)

200

How do you call a function named my_function?

my_function()

200

Write a simple while loop that prints numbers from 1 to 5.

i = 1

while i <= 5: 

     print(i)

     i += 1

200

What will be the output of len((10, 0, 3))

3

300

How do you loop through a list to print each item?

for loop

300

 Can you change the values inside a tuple after it is created?

No, tuples are immutable.

300

 What is the purpose of the return statement in a function?

It sends back a value from the function.

300

Write a simple for loop that prints numbers from 10 to 1.

for x in range (10, 0, -1):

    print(x)

300

 What is the difference between lists and tuples in Python?

Lists are mutable; tuples are immutable

400

 What method would you use to remove an item from a specific index in a list?

pop(index)

400

How do you access the first item of a tuple called my_tuple

my_tuple[0]

400

Write the syntax to create a function that returns the area of a rectangle.

 def area(a, b): 

        return a * b

400

 What is the output of the following code:

for i in range(100, 30, -20): 

     print(i)

100, 80, 60, 40

400

 How do you define a function that takes two parameters: x,y?

def function_name(x,y):

500

Write a one-line code to calculate the sum of all numbers in a list called my_list.

sum(my_list)

500

What function can you use to convert a list to a tuple?

tuple(list)

500

What is the output of the following code:

def triangle(base, h):
    area=1/2*base*h
    return area
print(triangle(10,7))

35.0

500

What is the output of the following code:

x=100
sum=0
while x>10:
    sum+=1
    x-=20
print(sum)

5

500

Write a code to create a list of random 10 numbers.

import random
list=[]
for i in range(10):
    list.append(random.randint(1,100))
print(list)