import random #imports the module random Q_num = 13 # the total number of questions in the quiz print() print ("This is Simon's quiz on Python for the Data Dcience and KI course 2023 from PoGS") #welcome print() total_score = 0 #initial total score to zero print('Your current total score is', total_score, 'point(s)') #score message print() input('Press enter to start the quiz') # user input print() order = list(range(1,Q_num+1)) #creates the list "order" which contains the question numvers random.shuffle(order) # mutates list "order": objects contained (question numbers)are shuffled for random order of questions for b in order: # loops over the list "random" which contains the question identifiers in random order Q = b #question identifier "Q" is interated over list "order" containing question numbers #Question 1 - number naive data structures if Q == 1: #question identifier print() print() print('Question', Q,':') #prints the question print() new_points = 1 # definiton of points for exercise A = 'empty' # variable is created for user answers A = input('How many naive data structures are there in Python?') #user input if A == '4' or A == 'four': #two answers are possible total_score = total_score + new_points #if correct answer, point is added to total score print() print('Well done! You gained', new_points, 'point(s). Your current total score is', total_score, 'point(s)') else: print() print('The correct answer is 4. You do not get any points. You score is still', total_score, 'point(s)') print() input('Press enter to continue') #Question 2 - list mutation if Q == 2: print() print() print('Question', Q,':') print() new_points = 1 # definiton of points for exercise A = 'empty' # variable is created for user answers while A not in ['yes', 'no', 'skip']: #loop over user input to force user input A = input('Lists are mutable. Type "yes" or "no". You can skip the question by enter "skip"') if A == 'yes': total_score = total_score + new_points print() print('Well done! You gained', new_points, 'point(s). Your current total score is', total_score, 'point(s)') else: print() print('The correct answer is "yes". You do not get any points. You score is still', total_score, 'point(s)') print() input('Press enter to continue') #Question 3 - list assignment if Q == 3: print() print() print('Question', Q,':') print() new_points = 1 # definiton of points for exercise A = 'empty' # variable is created for user answers while A not in ['yes', 'no', 'skip']: A = input('For assignment of lists, curly brackets are used. Type "yes" or "no". You can skip the question by enter "skip"') if A == 'no': total_score = total_score + new_points #calculate new score print() print('Well done! You gained', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() else: print() print('The correct answer is "no". Square brackets are used. You do not get any points. You score is still', total_score, 'point(s)') print() input('Press enter to continue') #Question 4 - Dictionaries if Q == 4: A = [] # list is created for user answers statements = { #dictionary is created with statements and answers as key/value pair 'Dictionaries are immutable' : 'no', 'Dictionaries contain key/value pairs' : 'yes', 'A key/value pair is sperated from the next by colon (:)' : 'no', 'Dictionaries are enclosed by curly brackets' : 'yes', 'The insertion order in dictionaries is maintained' : 'no', 'The key in dictionaries is usually a string and the key can be any object' : 'yes', 'The lookup algorithm in key in dictionaries is rather slow' : 'no', 'In a dictonary the key is seperated from is value by a comma (,)' : 'no', 'The key needs to be enclosed in quotes in case it is a string' : 'yes' } print() print() print('Question', Q,': Following characteristics apply for dictionaries.') print() print() for k,v in statements.items(): #iterate over key and value in statements dictionary. print(k) #only statements are printed print() A.append(input('Type "yes" or "no" as answer.')) #auser input, append user answers into list print() print() print('This is what a dictionary assigment may look like:') print("ex_dict = {'key1' : 'value1', 'key2' : 'value2', 'key3' : 42}") #example for dict print() print('Those are the correct answers') count = -1 #counter for index in list with user answers new_points = 0 #new point counter for k,v in statements.items(): #interate over key and value in statements count += 1 #increment of index counter print() print('Statement:', k) #print statement print('Answer: ', v) #print correct answer if A[count] == v: #checks if user answer was correct (entry in list "A" is same as value in dict "statements" new_points += 1 #one point is rewarded per correct answer print('Well done! Your answer was correct! You score 1 point.') else: print('Your answer "',A[count], '" was not correct. No points here.') #wrong answer is repeated total_score = total_score + new_points #calculate new total score print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() input('Press enter to continue') #Question 5 - Tuples #same style as Q4 if Q == 5: A = [] statements = { 'Tuples cannot be changed once defined.' : 'yes', 'For assignment of tuples curly brackets "{" and "}"are used' : 'no', 'The order of values in tuples is not maintained' : 'no', 'Tuples are not allowed to contain dublicates' : 'no', 'Tuples are indexable and their index starts with 1' : 'no', 'Values for assignmnet are seperated by comma' : 'yes', 'Tuples can only contain objects of one type, e.g. string or interger' : 'no' } print() print() print('Question', Q,': Following characteristics apply for tuples') print() print() for k,v in statements.items(): print(k) print() A.append(input('Type "yes" or "no" as answer.')) print() print() print('This is what a tuple assigment may look like:') print("ex_tup = ('a', 'c', 1, 17, 'a')") print() print('Those are the correct answers') count = -1 new_points = 0 for k,v in statements.items(): count += 1 print() print('Statement:', k) print('Answer: ', v) if A[count] == v: new_points += 1 print('Well done! Your answer was correct! You score 1 point.') else: print('Your answer "',A[count], '" was not correct. No points here.') total_score = total_score + new_points print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() input('Press enter to continue') #Question 6 - Sets #same style as Q4 if Q == 6: A = [] statements = { 'Sets are immutable.' : 'no', 'Set assignment is done by enclosing comma (,) seperated objects with curly brackets "[" and "}"' : 'yes', 'Using expression "ex_set = set{1,2,3,4,5}" generates a set containing integers' : 'no', 'Using the "set" function on a sequence always generates sets containing objects of class "string"' : 'yes', 'Sets always contain objects of class "string"' : 'no', 'Sets are ordered' : 'no', 'Sets contain unique objects' : 'yes', 'Sets are indexable, their index starting with 0' : 'no' } print() print() print('Question', Q,': Following characteristics apply for sets') print() print() for k,v in statements.items(): print(k) print() A.append(input('Type "yes" or "no" as answer.')) print() print() print('This is what a set assigment may look like:') print("ex_set1 = {'a', 'b', 'c', 10, 100}") print("or when using the 'set' function on a sequence:") print("ex_set2 = set('simon was here')") print() print('Those are the correct answers') count = -1 new_points = 0 for k,v in statements.items(): count += 1 print() print('Statement:', k) print('Answer: ', v) if A[count] == v: new_points += 1 print('Well done! Your answer was correct! You score 1 point.') else: print('Your answer "',A[count], '" was not correct. No points here.') total_score = total_score + new_points print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() input('Press enter to continue') #Question 7 - Lists #same style as Q4 if Q == 7: A = [] statements = { 'Lists are mutable.' : 'yes', 'List assignment is done by enclosing comma (,) seperated objects with round brackets "(" and ")"' : 'no', 'Using expression "no0 = list("1,2,3,4,5")" generates a list containing 5 string objects' : 'yes', 'Lists usually containing string objects' : 'no', 'The method "extend()" is used on a list by dot-notation syntax' : 'yes', 'Imagine two lists: no1 = [1, 2, 3] and no2 = [4, 5], the promp "no3 = no1.extend(no2)" gives "no3 = [1, 2, 3, 4, 5]"' : 'no', 'Imagine two lists: no4 = [0, 4, 17] and no5 = [2, 6], the promp "no4.append(no5)" gives "no4 = [0, 4, 17, 2, 6]"' : 'no', 'Imagine two lists: no6 = [55, 80] and no7 = [45, 2], the promp "no7.extend(no6)" gives "no1 = [45, 2, 55, 80]"' : 'yes', 'Lists are ordered and indexable, their index starting with 0' : 'yes', 'Lists may contain dublicates' : 'yes', 'To access a single value in a lists, the corresponding index surrounded by round brackets behing the list name is used' : 'no' } print() print() print('Question', Q,': Following characteristics apply for lists') print() print() for k,v in statements.items(): print(k) print() A.append(input('Type "yes" or "no" as answer.')) print() print() input('Press enter to continue') print() print('This is what a set assigment may look like:') print("ex_list1 = ('a', 'b', 'c', 10, 100)") print("or when using the 'list' function on a sequence:") print() print("ex_list2 = list('happy to be here')") print('Note that ex_list2 contains 16 string objects') print() input('Press enter to continue') print() print('Those are the correct answers:') count = -1 new_points = 0 for k,v in statements.items(): count += 1 print() print('Statement:', k) print('Answer: ', v) if A[count] == v: new_points += 1 print('Well done! Your answer was correct! You score 1 point.') else: print('Your answer "',A[count], '" was not correct. No points here.') print() input('Press enter to continue') print() total_score = total_score + new_points print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() input('Press enter to continue') #Question 8 - Built-in functions if Q == 8: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions print() print() print('Question', Q,': Name 6 built-in functions. Include argument parantheses, e.g. "bool()" not "bool" ') print() print() input('Press enter to continue') print() for i in range(1,7): # loops times for 6 user inputs A.add(input('Name built-in function '+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(BIF) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in functions') print() if go == 'show': #option to show all possible answers for i in sorted(BIF): print(i) print() input('Press enter to continue') #Question 9 - Built-in dictionary methods #same style as Q8 if Q == 9: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions DICM = {'clear()', 'copy()', 'fromkeys()', 'get()', 'items()', 'keys()', 'pop()', 'popitem()', 'setdefault()', 'update()', 'values()'} #DICM is a set containing built-in dictionary methods SETM = {'add()', 'clear()', 'copy()', 'difference()', 'difference_update()', 'discard()', 'intersection()', 'intersection_update()', 'isdisjoint()', 'issubset()', 'issuperset()', 'pop()', 'remove()', 'symmetric_difference()', 'symmetric_difference_update()', 'union()', 'update()'} #SETM is a set containing built-in set methods TUPM = {'count()', 'index()'} #TUPM is a set containing built-in tuple methods LISM = {'append()', ' clear()', 'copy()', 'count()', 'extend()', 'index()', 'insert()', 'pop()', 'remove()', 'reverse()', 'sort()'} #LISM is a set containing built-in list methods print() print() print('Question', Q,': Name 2 built-in dictionary methods. Include argument parantheses, e.g. "copy()" not "copy" ') print() print() input('Press enter to continue') print() for i in range(1,3): # loops times for user inputs A.add(input('Name built-in dictionary method'+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(DICM) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in dictionary methods') print() if go == 'show': #option to show all possible answers for i in sorted(DICM): print(i) print() input('Press enter to continue') #Question 10 - Built-in set methods #same style as Q8 if Q == 10: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions DICM = {'clear()', 'copy()', 'fromkeys()', 'get()', 'items()', 'keys()', 'pop()', 'popitem()', 'setdefault()', 'update()', 'values()'} #DICM is a set containing built-in dictionary methods SETM = {'add()', 'clear()', 'copy()', 'difference()', 'difference_update()', 'discard()', 'intersection()', 'intersection_update()', 'isdisjoint()', 'issubset()', 'issuperset()', 'pop()', 'remove()', 'symmetric_difference()', 'symmetric_difference_update()', 'union()', 'update()'} #SETM is a set containing built-in set methods TUPM = {'count()', 'index()'} #TUPM is a set containing built-in tuple methods LISM = {'append()', ' clear()', 'copy()', 'count()', 'extend()', 'index()', 'insert()', 'pop()', 'remove()', 'reverse()', 'sort()'} #LISM is a set containing built-in list methods print() print() print('Question', Q,': Name 5 built-in set methods. Include argument parantheses, e.g. "copy()" not "copy" ') print() print() input('Press enter to continue') print() for i in range(1,6): # loops times for user inputs A.add(input('Name built-in set method '+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(SETM) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in set methods') print() if go == 'show': #option to show all possible answers for i in sorted(SETM): print(i) print() input('Press enter to continue') #Question 11 - Built-in list methods #same style as Q8 if Q == 11: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions DICM = {'clear()', 'copy()', 'fromkeys()', 'get()', 'items()', 'keys()', 'pop()', 'popitem()', 'setdefault()', 'update()', 'values()'} #DICM is a set containing built-in dictionary methods SETM = {'add()', 'clear()', 'copy()', 'difference()', 'difference_update()', 'discard()', 'intersection()', 'intersection_update()', 'isdisjoint()', 'issubset()', 'issuperset()', 'pop()', 'remove()', 'symmetric_difference()', 'symmetric_difference_update()', 'union()', 'update()'} #SETM is a set containing built-in set methods TUPM = {'count()', 'index()'} #TUPM is a set containing built-in tuple methods LISM = {'append()', 'clear()', 'copy()', 'count()', 'extend()', 'index()', 'insert()', 'pop()', 'remove()', 'reverse()', 'sort()'} #LISM is a set containing built-in list methods print() print() print('Question', Q,': Name 6 built-in list methods. Include argument parantheses, e.g. "copy()" not "copy" ') print() print() input('Press enter to continue') print() for i in range(1,7): # loops times for user inputs A.add(input('Name built-in list method '+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(LISM) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in list methods') print() if go == 'show': #option to show all possible answers for i in sorted(LISM): print(i) print() input('Press enter to continue') #Question 12 - list methods that can't be used on sets #same style as Q8 if Q == 12: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions DICM = {'clear()', 'copy()', 'fromkeys()', 'get()', 'items()', 'keys()', 'pop()', 'popitem()', 'setdefault()', 'update()', 'values()'} #DICM is a set containing built-in dictionary methods SETM = {'add()', 'clear()', 'copy()', 'difference()', 'difference_update()', 'discard()', 'intersection()', 'intersection_update()', 'isdisjoint()', 'issubset()', 'issuperset()', 'pop()', 'remove()', 'symmetric_difference()', 'symmetric_difference_update()', 'union()', 'update()'} #SETM is a set containing built-in set methods TUPM = {'count()', 'index()'} #TUPM is a set containing built-in tuple methods LISM = {'append()', 'clear()', 'copy()', 'count()', 'extend()', 'index()', 'insert()', 'pop()', 'remove()', 'reverse()', 'sort()'} #LISM is a set containing built-in list methods LISMonly = LISM.difference(SETM) print() print() print('Question', Q,': Name 3 built-in list methods that cannot be used on sets. Include argument parantheses, e.g. "sort()" not "sort" ') print() print() input('Press enter to continue') print() for i in range(1,4): # loops times for user inputs A.add(input('Name built-in list method '+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(LISMonly) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in list methods that cannot be used on sets') print() if go == 'show': #option to show all possible answers for i in sorted(LISMonly): print(i) print() input('Press enter to continue') #Question 13 - list & set methods #same style as Q8 if Q == 13: # identifier for list "order" to allow random order of questions A = set() # empty set is created for user answers BIF = {'abs()', 'aiter()', 'all()', 'any()', 'anext()', 'ascii()', 'bin()', 'bool()', 'breakpoint()', 'bytearray()', 'bytes()', 'callable()', 'chr()', 'classmethod()', 'compile()', 'complex()', 'delattr()', 'dict()', 'dir()', 'divmod()', 'enumerate()', 'eval()', 'exec()', 'filter()', 'float()', 'format()', 'frozenset()', 'getattr()', 'globals()', 'hasattr()', 'hash()', 'help()', 'hex()', 'id()', 'input()', 'int()', 'isinstance()', 'issubclass()', 'iter()', 'len()', 'list()', 'locals()', 'map()', 'max()', 'memoryview()', 'min()', 'next()', 'object()', 'oct()', 'open()', 'ord()', 'pow()', 'print()', 'property()', 'range()', 'repr()', 'reversed()', 'round()', 'set()', 'setattr()', 'slice()', 'sorted()', 'staticmethod()', 'str()', 'sum()', 'super()', 'tuple()', 'type()', 'vars()', 'zip(), __import__()'} #BIF is a set containing built-in functions DICM = {'clear()', 'copy()', 'fromkeys()', 'get()', 'items()', 'keys()', 'pop()', 'popitem()', 'setdefault()', 'update()', 'values()'} #DICM is a set containing built-in dictionary methods SETM = {'add()', 'clear()', 'copy()', 'difference()', 'difference_update()', 'discard()', 'intersection()', 'intersection_update()', 'isdisjoint()', 'issubset()', 'issuperset()', 'pop()', 'remove()', 'symmetric_difference()', 'symmetric_difference_update()', 'union()', 'update()'} #SETM is a set containing built-in set methods TUPM = {'count()', 'index()'} #TUPM is a set containing built-in tuple methods LISM = {'append()', 'clear()', 'copy()', 'count()', 'extend()', 'index()', 'insert()', 'pop()', 'remove()', 'reverse()', 'sort()'} #LISM is a set containing built-in list methods LISMonly = LISM.difference(SETM) #set listing list only methods SLM = LISM.intersection(SETM) #set listing list and set methods print() print() print('Question', Q,': Name 3 built-in methods that can be used on both, sets and lists. Include argument parantheses, e.g. "clear()" not "clear" ') print() print() input('Press enter to continue') print() for i in range(1,4): # loops times for user inputs A.add(input('Name built-in list method '+ str(i)+':')) #adds user anwer to set print() inboth = A.intersection(SLM) #intersection gives correct answers new_points = len(inboth) #len gives number of correct answer -> new points total_score = total_score + new_points #adds new points to total score print('Those were your (unique) answers:') for i in A: # prints all answers print(i) print() input('Press enter to continue') print() print('Following',len(inboth), 'answer(s) were correct:') for i in inboth: print(i) #prints all correct answers print() print('You scored', new_points, 'point(s). Your current total score is', total_score, 'point(s)') print() go = input('Press enter to continue or "show" for showing all built-in methods that can be used onboth, sets and lists') print() if go == 'show': #option to show all possible answers for i in sorted(SLM): print(i) print() input('Press enter to continue') #dont forget to indent when adding new questions here! #more topics to include: IDLE, editor, shell, objects, variables, loops (for, while, range, indention), slicing, if/elif/else, slicing, help, dir, type, bool, items, list manipulation, dict assignment, dict of dict, set methods, modules & functions, PEP else: print() print('Congratulations! You finished the quiz. Your scored', total_score, 'point(s)')