Write a programBasic10 XPExercise 6/15

A random list reversed

Task

The user enters how many elements the list should have. The program creates a list of that many random whole numbers from ⟨−100; 100⟩, prints it and then prints it again in reverse order.

Split it into functions the tests call directly:

  • vygeneruj(pocet) returns a list of pocet random whole numbers from −100 to 100,
  • naopak(zoznam) returns a new list with the elements in reverse order; it does not change the original list.

Examples

  • Call

    print(naopak([1, 2, 3]))

    Expected output

    [3, 2, 1]
  • Call

    z = [5, -7, 9]
    n = naopak(z)
    print(z)
    print(n)

    Expected output

    [5, -7, 9]
    [9, -7, 5]
  • Call

    z = vygeneruj(50)
    print(len(z), all(type(x) == int and -100 <= x <= 100 for x in z))
    print(len(set(vygeneruj(50))) > 1)

    Expected output

    50 True
    True

After you submit, 2 hidden tests will also check your solution: an empty list, one element.

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.