Week 1 ~ 2
Week 3 ~ 4
Week 5 ~ 6
Week 7 ~ 8
Week 9 ~ 10
100
What is python?

A scripting language! Though Programming Language is also accepted.

100
What is branching?
Branching allows conditions to be placed to achieve different results.
100

What is the difference between a for loop and a while loop?

For loops typically has a set boundary of numbers to iterate through at the second when the for i in something is processed.

While loops typically does not know when the loop will end, thus it can go infinite.

100

Define what is a function?

function is where you have an input and an output.

100

What are the three modes in opening a file?


Could you also name the hiearchy of it? Such if implemented in one mode, it will also give access to another mode.


Read, Write, Append


Yes, write also implies read, append also implies read. Read does NOT imply write or append.
200

Name at least 6 basic built-in types for python

String, Int, Float, Bool, List, Dict, Tuple, Set

200

What are implicit & explicit bounds?

Explicit bound states an upper and lower bound while implicit only state one of them.
200

How would you iterate over a 2-D list? (each inner list may have a different length)

You can set up 2 for loops like this:

for i in range(len(L)):

    for j in range(len(L[i]))


for i in L:

    for j in i:

200
What is the return statement do in functions? 


EC: What will happen if you do not include a return, what is the default value that any functions return?


return functions gives the output to wherever a function call occured. 

default return is None.
200

What is the better way of opening files so that you don't have to worry about file closing?

the "with" operator.

300

Name the difference between List, Set, Dict and Tuple

List -> Basic container type

Dict -> allow key and value pairs, key must be immutable

Set -> disallow duplicates.

Tuple -> immutable

300
What are list indexing and how to perform list slicing?

List indexing is when you do L[0] or L[1]

List slicing is L[0:10]

300

Name 2 ways that you can iterate over a dictionary.

If find a third way that uses both a .keys() and .values() method, then EC!

for k,v in dict.items()

or 

for k in dict:

# k is key, then dict[k] is val

or 

for k,v in zip(dict.keys(),dict.values()):



300

What is the difference between pre and post condition asserts?

Pre usually goes inside the function and test to see if parameter or inputs are correct or not.

Post usually goes outside the function, typically after the function call, to test if the output is the expected output.
300

What is a csv file, what is the pattern inside the file?

csv are comma separated values, which are usually separated by commas. NOTE that there are no spaces around the comma usually.


Example:

name,ID,year

hitoki,123,2025

sam,234,2026

john,589,2027





400

Write a code such that it defines a namedtuple of four fields called "Student", the four field can be anything. Then actually use this Student namedtuple to make a dummy tuple.

from collections import namedtuple

Student = namedtuple("Student",["name", "ID", "classEnrolled", "year"])

hitoki = Student("Hitoki", "123456789", ["ICS31","ICS32"], 2)


400
Given a list of integers, how can you sort it by reverse? Do this in one line

sorted(L, reverse = True)

400

Name 3 functions that you can use over a list so that it helps in using loops. like range()

range()

enumerate()

zip()


400

What are try-except-finally? Write an example that will cause an error to occur and your except should catch it.


EC: What is "raise"?

Try except finally block allows testing code to see if it works, then if it does not work then there is a corresponding code that match with the error as a second plan. Note the finally block will always run no matter what.

raise is to manually create an error. Syntax is raise TypeError
400

What value of x in the following code will print True?


print(True if (x % 2 == 0) and x>50 else True if (x==4) else False)

True if x is even and if x is over 50, or that if it is equal to 4 then print True. Otherwise print False

500
Define mutability in two distinctive ways.

1) When an object can be modified without reassignment.

2) When an object can use any in-place operators.

500

What is the output of this?


not(not True and False or True or False) and not True or False or not (False) and True

True!

500
Write out a code that extracts the minimum from a 1-D list. The final list will not contain the minimum anymore. Do not use the min() function.

min = None

for i in L:

    if i < min:

        min = i

L.remove(min)


or


sList = sorted(L)

L.remove(sList[0])


500

What are *args and **kwargs? What are the rules in writting them? What is the format of the two variables if you want to access them in your function?

*args can contain any number of positional arguments where **kwargs can contain any number of keyword arguments.
500

What is the output of the following list comprehension?


[[x+y for y in range(x)] for x in range(3,-1,-1)]

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