Skip to content

Exercise 1

Problem 1

You need to inspect the url printed by your code to extratct the link. Two situations are listed below:

  • A url can be absolute (i.e. full name is specified). An example is https://xkcd.com/ where http is the protocol, :// are the separators, xkcd is the name, and com is domain.
  • A url can be relative (i.e. a path from current address onwards is given). Fo example, on https://xkcd.com/ the link to https://xkcd.com/archive/ is specified merely as /archive.

Your task is to:

  1. Identify whether a url is relative or absolute
  2. Identify the protocol and domain
  3. Having been able to better understand what a url is composed of, there is no harm in saving it to a CSV file. Please go ahead a use your favirote search engine to search how data (a string in this case) can be saved in a CSV file and complete the task.

Your solution should be in the form of Python code added below the link extraction code.

Note

Ignore any other possibilities that come along. You are free to make your assumptions where neeeded!

Problem 2

Given a variable var, that contains the value of any decimal number, write Python code to print the whole number nearest to var. For example: var = 3.14159 shoul result in 3, and var = 23.63 should print out 24.

Hint

A Python function that you can use (not already introduced in Unit 1) is str(<num>) that converts the num to a string. For example, str(45) will give you '45' as a string.

** God willing, see you again :)

Back to top