import time score = 0 questions = { '"Is a function a) part of a module or b) stored directly in the standard library? - Type in a or b":': 'a', '"Which kind of loop do you use, when you do not know in advance how many times you need to iterate. - Type in for or while":': 'while', '"What does the following line of code give you? random.randint(4, 7) gives a random number between 4 and":': '7', '"Which list does the following code produce? list(range(15, 2, -3)). Write down your answer in list notation.":': '[15, 12, 9, 6, 3]', '"What is a list? a) an ordered mutable collection of objects? b) an ordered immutable collection of objects, c) an unordered set of key/value pairs, d) an unordered set of unique objects? - Type in a, b, c or d":': 'a', '"A list is like an array — the objects it stores are ordered sequentially in slots, beginning with slot number... (enter an integer): "': '0', '"Which code does give you the correct manipulation result of the list nums = [1, 3, 4] --> nums = [1, 2, 3, 4]. a) nums.remove(2), b) nums.pop(2), c) nums.extend([2]), d) nums.insert(1, 2) - Type in a, b, c or d":': 'd', '"What slice is the result for phraselist containing the elements of the phrase "Python is beautiful." when you prompt: phraselist[7:9:]? - Type in as a list":': "['i', 's']", '"What does the setdefault function do? It makes sure that your dictionary is a) not empty, b) ordered, c) reset to the initial state, d) emptied. - Type in a, b, c or d":': 'a', '"Which operation does not work on sets? a) union, b) difference, c) intersection, d) save duplicates. - Type in a, b, c or d":': 'd', '"Dictionaries are randomly ordered in Python. Which function gives you an ordered output of your dictionary (from A-Z): a) aligned, b) ordered, c) sorted, d) alphabet. - Type in a, b, c or d":': 'c', '"Put the elements of the function in the right order: a) vowels = set('u'), b) return vowels.intersection(set(phrase)), c) """Return vowel u found in a supplied word.""", d) def search4vowels(phrase: str) -> set: - Type in the correct sequence of abcd":': 'dcab', '"Which (immutable) data structure is not passed into a function by reference? a) lists, b) dictionaries, c) tuples, d) sets? - Type in a, b, c or d":': 'c', '"What is an important standard to write Python code? a) UGLY 2, b) NICE 3, c) PEP 8, d) MUST 9. - Type in a, b, c or d":': 'c', } print('**************************************') print('Welcome to Timo\'s Python Quiz Program') print('**************************************') time.sleep(2) print('Are you ready? - Lets go!') print('') time.sleep(1) print('Let\'s start with an easy question.') print(' ') time.sleep(1) for q, a in questions.items(): answer = input(q + " ") if answer == a: print('Correct.') score +=1 else: print('false.') print(score) print('') time.sleep(1) print('**************************************') if score < 8: print("Final score:", score,"/14. You can do better.") else: print("Final score:", score,"/14. Passed. Congrats.") print('The end.') print('**************************************') time.sleep(3)