import time def open_que(question:str, answer:str) -> int: """Ask an open question.""" print(question) user_answer = input("Your answer:") if user_answer == answer: print("Correct!") time.sleep(1) print() return 1 else: print("False, the correct answer is:", answer) time.sleep(1) print() return 0 def mult_que(question:str, options:list, answer:int) -> int: """Ask a multiple choice question""" print(question) j = 0 for i in options: print(j, "-", i) j += 1 user_answer=int(input("Your answer:")) if user_answer == answer: print("Correct!") time.sleep(1) print() return 1 else: print("False, the correct answer is:", options[answer]) time.sleep(1) print() return 0 cor_ans = 0 cor_ans += open_que("Which module helps you interact with your operating system?","os") cor_ans += mult_que("Tuples are...", ["mutable", "not mutable"],1) cor_ans += mult_que("Lists are...", ["ordered", "not ordered"],0) cor_ans += mult_que("Dictionaries are...", ["ordered", "not ordered"],1) cor_ans += mult_que("Sets are introduced with...", ["square brackets [", "round brackets (", "curved brackets {"],2) cor_ans += open_que("Which method lets you create a set that includes all objects of two sets?", "union()") cor_ans += mult_que("What is a shortcut for found['e'] = found['e']+1", ["found['e']+1 = found['e]","found['e'] += 1","found['e'] =+ 1", "found['e'] = +1"], 1) cor_ans += mult_que('Which of these functions removes and returns the object of a list based on the index x?', ["extend(x)","insert(x)","remove(x)","pop(x)"],3) cor_ans += mult_que("What is the grammar of the slicing method?", ["[start:stop:step]","[step:start:stop]","[stop:step:start]"],0) cor_ans += mult_que("which data type does the items() method work with?", ["Lists","Sets","Dictionaries","Tuples"],2) cor_ans += mult_que("How do you introduce a function",["fun","funct","def","defin","in","intr"],2) cor_ans += open_que("Functions are stored and can be downloaded in", "modules") print("You got", cor_ans,"out of 12 questions right.")