TODO
Task 1
Create a script wikiPython.py that:
reads a Wikipedia page:
https://en.wikipedia.org/wiki/Python_(genus)(userequestscommand)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 Bucharesttest 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 datetimethe uptime of the machine using
uptimehow much disk
dfand memory usagefreeusingimport psutil
Questions
What is the difference between
requestsandcurl?requestsis a Python library,curlis a command line toolrequestsis a command line tool,curlis a Python libraryrequestsis a Python library,curlis a Python modulerequestsis a Python module,curlis a Python library
What will the following code output?
print(type(3.5))
<class ‘int’>
<class ‘float’>
<class ‘string’>
<class ‘decimal’>
What is the correct syntax to open a file for reading as a text file?
open(‘file.txt’, ‘r’)
open(‘file.txt’, ‘w’)
open(‘file.txt’, ‘rb’)
open(‘file.txt’, ‘wb’)
Which of the following is not a core data type in Python?
Lists
Arrays
Tuples
Dictionaries
In Python, what is a lambda function?
A named function, defined with the def keyword
An anonymous function, defined with the lambda keyword
A built-in function
A function that can only be used once
Which of the following data types does NOT allow duplicate elements?
list
tuple
set
dictionary
What is the output of the following tuple operation?
my_tuple = (1, 2, 3, 4) print(my_tuple[1:3])
(1, 2)
(2, 3)
(3, 4)
(2, 3, 4)
Answers
Answer: a
Explanation:
requestsis a Python library,curlis a command line toolAnswer: b
Explanation: The number 3.5 is a floating-point number, so Python will recognize it as a float type.
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.
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.
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.
Answer: c
Explanation: Sets are unordered collections of unique elements. Lists, tuples, and dictionaries can all contain duplicate elements.
Answer: b
Explanation: The slice [1:3] will return the second and third elements of the tuple, which are 2 and 3.