Test 5: Short Questions – Part 2

Short questions

25 questions · 50 min · 63 marks

Want to try first? Take the free Computer Science test: 94hbp-7gz9m-ufent-tsj4r

Sample questions with answers

The first 5 of 25, each with a model answer. Try writing yours first.

  1. Question 1 · 2 marks

    What is a library in Python?

    Show model answer

    Libraries are like toolboxes or pre-built toolkits full of useful tools that help you solve different problems without having to build everything from scratch.

  2. Question 2 · 2 marks

    How do you import a library in Python?

    Show model answer

    A library is imported using the import keyword, for example import random or import statistics.

  3. Question 3 · 3 marks

    Write a program to generate a random number between 1 and 10 using the random library.

    Show model answer

    import random number = random.randint(1, 10) print("The random number is:", number)

  4. Question 4 · 3 marks

    Write a program to calculate the mean of the list [23, 45, 67, 89, 12, 44, 56] using the statistics library.

    Show model answer

    import statistics

    data = [23, 45, 67, 89, 12, 44, 56]

    mean_value = statistics.mean(data)

    print("The mean value is:", mean_value)

    Output: The mean value is: 48

  5. Question 5 · 2 marks

    Why should you only import the libraries you need?

    Show model answer

    When importing libraries, make sure to only import what you need. More libraries can be explored at docs.python.org/3/.

More tests in Control Structures in Python

Practise with a free account

Save your scores, see which chapters need work, and keep a notebook of every question you got wrong.

Create free account