TODO

Task 1

Create a script wikiPython.py that:

  • reads a Wikipedia page: https://en.wikipedia.org/wiki/Python_(genus) (use requests command)

  • extracts Species elements - python name (what kind of pythons are there) (use BeautifulSoup)

  • save the output the to a new file

  • append to the new file the last line that is the count of species

Task 2

Create script weather.py that gives you the weather from curl https://wttr.in/(location)

  • the location will be read from the keyboard - for example weather Bucharest

  • test that location is valid using https://nominatim.openstreetmap.org/search?format=json&q= + location

Task 3

Create a health check script healthCheck.py that looks at:

  • date and time using import datetime

  • the uptime of the machine using uptime

  • how much disk df and memory usage free using import psutil

Questions

  1. What is the difference between requests and curl?

    1. requests is a Python library, curl is a command line tool

    2. requests is a command line tool, curl is a Python library

    3. requests is a Python library, curl is a Python module

    4. requests is a Python module, curl is a Python library

  2. What will the following code output?

    print(type(3.5))
    
    1. <class ‘int’>

    2. <class ‘float’>

    3. <class ‘string’>

    4. <class ‘decimal’>

  3. What is the correct syntax to open a file for reading as a text file?

    1. open(‘file.txt’, ‘r’)

    2. open(‘file.txt’, ‘w’)

    3. open(‘file.txt’, ‘rb’)

    4. open(‘file.txt’, ‘wb’)

  4. Which of the following is not a core data type in Python?

    1. Lists

    2. Arrays

    3. Tuples

    4. Dictionaries

  5. In Python, what is a lambda function?

    1. A named function, defined with the def keyword

    2. An anonymous function, defined with the lambda keyword

    3. A built-in function

    4. A function that can only be used once

  6. Which of the following data types does NOT allow duplicate elements?

    1. list

    2. tuple

    3. set

    4. dictionary

  7. What is the output of the following tuple operation?

    my_tuple = (1, 2, 3, 4)
    print(my_tuple[1:3])
    
    1. (1, 2)

    2. (2, 3)

    3. (3, 4)

    4. (2, 3, 4)

Answers

  1. Answer: a

    Explanation: requests is a Python library, curl is a command line tool

  2. Answer: b

    Explanation: The number 3.5 is a floating-point number, so Python will recognize it as a float type.

  3. Answer: a

    Explanation: The open() function opens a file in one of three modes: read, write, or append. The default mode is read. In this case, the file will be opened for reading as a text file.

  4. Answer: b

    Explanation: Arrays are not a core data type in Python; lists can be used where arrays are used in other languages. However, arrays can be used by importing the array module.

  5. Answer: b

    Explanation: A lambda function is an anonymous function that can be defined without a name. It is defined with the lambda keyword, not the def keyword.

  6. Answer: c

    Explanation: Sets are unordered collections of unique elements. Lists, tuples, and dictionaries can all contain duplicate elements.

  7. Answer: b

    Explanation: The slice [1:3] will return the second and third elements of the tuple, which are 2 and 3.