Write a programElementary20 XPExercise 11/15
Common elements of two lists
Task
The program generates two lists of 15 random whole numbers from ⟨1; 20⟩ and then a third list with the elements the first two share.
Split it into functions the tests call directly:
vygeneruj()returns a list of 15 random whole numbers from 1 to 20,spolocne(a, b)returns a list of the values found in both lists, each only once, sorted in ascending order.
What the program should do
spolocne([1, 2, 3, 4], [3, 4, 5]) returns [3, 4].
Examples
Call
print(spolocne([1, 2, 3, 4], [3, 4, 5]))
Expected output
[3, 4]
Call
z = vygeneruj() print(len(z) == 15, all(type(x) == int and 1 <= x <= 20 for x in z)) print(len({tuple(vygeneruj()) for _ in range(20)}) > 1)Expected output
True True True
After you submit, 3 hidden tests will also check your solution: repeated values, nothing in common, sorting the result.
Python starts the first time you run code.
Ctrl+Enter runs the program. Tab indents. Press Esc, then Tab, to leave the editor.
Input (stdin)
Each line = one call to input().
Output
Hints
Try it yourself first. Each hint reveals a little more - and lowers the reward a little.
Signed out, hints are free - but no XP is awarded either.
Solution
The solution unlocks after the last hint.