Write a programElementary20 XPExercise 3/9
Minimum, count and positions
Task
Write three functions:
nahodny_prvok(dolna, horna)returns a random whole number from ⟨dolna; horna⟩,vytvor_pole(dolna, horna)usesnahodny_prvokto build and return a list of 30 random elements from the given interval,analyza(pole)returns a triple (tuple)(minimum, pocet, pozicie): the smallest element, how many times it occurs and a list of its positions (indexes from 0).
The main program under if __name__ == "__main__": reads the bounds, builds the array and prints the results.
What the program should do
analyza([5, 3, 8, 3, 9]) returns (3, 2, [1, 3]).
Examples
Call
print(analyza([5, 3, 8, 3, 9]))
Expected output
(3, 2, [1, 3])
Call
p = vytvor_pole(5, 9) print(len(p), all(type(x) == int and 5 <= x <= 9 for x in p)) print(len({tuple(vytvor_pole(1, 100)) for _ in range(10)}) > 1)Expected output
30 True True
After you submit, 5 hidden tests will also check your solution: one element, a negative minimum three times, the minimum at the end, equal bounds, vytvor_pole calls nahodny_prvok.
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.