The following cell creates a list of dictionaries with information about me and my brother Kanishka. This acts as a database for my quiz function to refer to.

QuizDb = []

# Dhruva's Info
QuizDb.append({
    "Firstname": "Dhruva",
    "Lastname": "Iyer",
    "Age": "15",
    "Height": "68 inches"
})

# Kanishka's Info
QuizDb.append({
    "Firstname": "Kanishka",
    "Lastname": "Iyer",
    "Age": "13",
    "Weight": "80 pounds"
})

I created this function which asks questions like a quiz about a list of dictionaries that is given to it. This will take the dictionaries created above and convert them into a series of questions.

def ask_questions(QDb):
    correct_cnt = 0
    total_cnt = 0
    for dict_item in QDb:
        person_name = dict_item['Firstname']
        for key in dict_item:
            if key == 'Firstname':
                continue
            else:
                question = "what is " + person_name + "'s " + key
                correct_answer = dict_item[key]  
                user_answer = input(question)
                if user_answer == "exit":
                    break
                total_cnt += 1
                if correct_answer == user_answer:
                    correct_cnt += 1
                    print("Your answer is correct")
                
                else:
                    print("Your answer is incorrect")
                
        if user_answer == "exit":
            print("Bye!")
            break
    print('you answered: ', correct_cnt, '/', total_cnt, "Correct")

ask_questions(QuizDb)
Your answer is correct
Your answer is correct
Your answer is correct
Your answer is correct
Your answer is correct
Your answer is correct
you answered:  6 / 6

This is a simple while loop function that takes two integers that you give it, and inclusively lists all the integers in between them from least to greatest. The first integer must be less than the second integer.

def list_num_inclusive(x,y):
    
    x = int(x)
    y = int(y)
    
    if x >= y:
        print("ERROR!!! Starting value must be less than ending value. Please try again.")
    else:
        print("Here are your numbers!!!")
    while x <= y:
        print(x)
        x += 1

starting_value = input("What is the starting value? (Inclusive")
ending_value = input("What is the ending value? (Inclusive")

list_num_inclusive(starting_value, ending_value)
Here are your numbers!!!
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

This is a function that uses a recursive loop, which means that when the function is defined, it calls for itself. This can create a loop that repeats itself until a specific condition is met. In this case takes a dictionary value and increments itself while adding itself to a sum. This creates a factorial like function, but for addition. For example if you input 1 into this function, it will take 1+2+3+4+5 = 15.

def example_recursive(x):
    x = int(x)
    if x < 10:
        x += 1
        x=example_recursive(x)
    else:
        print("End of recursive loop")
    return x

def example_recursive_dict(dict_obj, NN):
    #dict_obj['val'] = int(dict_obj['val'])
    print('inside example_recursive_dict, val is: ',dict_obj['val'])
    if dict_obj['val'] < NN:        
        dict_obj['val'] += 1
        dict_obj['sum'] += dict_obj['val'] 
        #print('inside if')
        example_recursive_dict(dict_obj, NN)
    else:
        print("End of recursive loop")
    

#recursive_var = input("What number should we start with?")
#recursive_var=example_recursive(recursive_var)
#print(recursive_var)


def example_by_reference(dict_obj):
    dict_obj['val'] += 1

dict_test = {'val': 2, 'sum': 0}
print(dict_test['val'])
example_by_reference(dict_test)
print(dict_test['val'])
example_by_reference(dict_test)
print(dict_test['val'])
dict_test['val'] = 0
dict_test['sum'] = 0
example_recursive_dict(dict_test, 5)
print('summation is done, value is: ', dict_test['sum'])
2
3
4
inside example_recursive_dict, val is:  0
inside example_recursive_dict, val is:  1
inside example_recursive_dict, val is:  2
inside example_recursive_dict, val is:  3
inside example_recursive_dict, val is:  4
inside example_recursive_dict, val is:  5
End of recursive loop
summation is done, value is:  15