Tuple
Set
Dictionary
Other
(points * 2)
Programs
(points * 5)
100

Create a tuple called tuple1 that contains 1, 2, 3, 4, 5

tuple1 = (1,2,3,4,5)

100

Create a set called set1 that contains 1, 2, 3, 4, 5

set1 = {1,2,3,4,5}

100

What are the two things included in a dictionary?

Key, Value

100

What is the symbol for modulo? 

And what does it mean?

%, it means the remainder from an integer division. 

100

Write a program that counts by 5, starts at zero and stops when it is over 100.
(Using while loop)

num = 0

while num < 100:
       num = num + 5

       print(num)

200

Does Tuple allow duplication of values?

Yes

200

Does Set allow duplication of values?

No

200

Create a dictionary called dict1 that contains 1, 2, 3 with their corresponding alphabet. The alphabet being the key.

dict1 = {"a":1, "b":2, "c":3}

200

Write a code that can find out the length of a list?

list1 = [ 1, 2, 3, 4, 5]

What is the answer?

print(len(list1))

5

200

Write a function called fun that takes in 3 arguments: first name, last name and the age of a person. And call the function so that is will print out the following: 

Hello, I am FirstName LastName and I am Age years old.

(Function uses def)

def fun(fname, lname, age):

___print("Hello, I am", fname ,lname, ",and I am", age ,"years old.")

fun("firstname", "lastname", 5)

300

Is a Tuple mutable?

Does order matter in a Tuple?

No

Yes

300

Is a Set mutable?

Does order matter in a Set?

Yes

No

300

Is a Dictionary mutable?

Does order matter in a Dictionary?

Yes

No

300

How do we create a random number generator thats chooses a number between 1 - 10.

import random

num = random.randint(1,10)

print(num)

300

Create a program that rolls a 20 sided dice randomly. And it keeps rolling until we rolled a 20. 

import random

num = 0

while num != 20:

    num = random.randint(1,20)

    print(num)

400

How to change the tuple from to include 1,2,3,4,5,6; and how to change the tuple to 1,2,3,4.

Tuple is unmutable / unchangeable so that means in order to have change the original tuple you have to create a new one. 

tuple1 = (1,2,3,4,5,6)

tuple1 = (1,2,3,4)

400

How to change a set from the original to include 1,2,3,4,5,6; and how to change a set to 1,2,3,4.

A Set is mutable / changeable so that means in order to have change the original tuple you add and remove.

set1.add(6)

set1.remove(5)

set1.pop(5)

set1.discard(5)

400

How to print a value from dict1, so it will print out 1.

print(dict1.get("a"))

400

Write a program that takes an input and output if the integer is even or odd.

num = int(input("Enter a number"))

if (num % 2 == 0):      

     print("It is even")

else:       

      print("It is odd")

400

Write a program that flips a coin until we exit the loop and counts the total of heads and tails.

(random and while)

import random

print("Welcome to the Python coin flip")

headC = 0

tailC = 0

while input("Press enter to flip the coin or type -1 to exit: ") != "-1":    

     coin = random.randint(0,1)    

     if(coin == 0):        

               print("Heads")        

               headC+=1   

     if(coin == 1):        

               print("Tails")        

               tailC+=1    

     print("Total Heads: " , headC , ", Total Tails: " , tailC)

500

Write a program to find the sum of the following tuple:

tuple1 = (18, 29, 45, 37, 56)

answer = 185

tuple1 = (18, 29, 45, 37, 56)

sum = 0

for num in tuple1:

___sum = num + sum

print (sum)

500

What will be printed out?

set1 = {12, True, 5.0, True, "apple", "banana", "cherry", "apple", 0, 2}

print(set1)

{12, True, 5.0, "apple", "banana", "cherry", 0, 2}

500

How to change a dictionary from the original to include a1,b2,c3,d4; and how to change a set to a1,b2.

dict1["d"] = 4

dict1.update({"d" : 4})


dict1.pop("c")

500

Write a program that takes an input of string and output the letter entered is a vowel or consonant.  

letter = str(input("Enter a letter"))

if(letter =='a'):   

        print("vowel")

elif(letter =='e'):    

        print("vowel")

elif(letter =='i'):    

        print("vowel")

elif(letter =='o'):    

         print("vowel")

elif(letter =='u'):    

       print("vowel")

else:    

       print("consonant")

500

Write a program that finds the min and max of the following list:

res = [70 , 80, 90, 100, -60, -50 , -40]

(for loop)

res = [70 , 80, 90, 100, -60, -50 , -40]

max = res[0]

for num in res[1: ]:   

     if(num > max):        

     max = num

print (max)


min = res[0]

for num in res[1: ]:   

     if(num < min):        

     min = num

print (min)

M
e
n
u