HTTP, URLs, and the query string (?…)

Beginner Data Science Praktikum
Created by Pavel · 21.03.2026 at 01:05 UTC · 1 completed

When you paste a link into the browser or call an API from Python, you are speaking HTTP: the client asks, the server answers with a status and a body. The address in the bar is a URL shaped like scheme://host/path?query#fragment.

The story often hinges on the part after ?: the query string, a chain of key=value pairs joined by &. In one thread you are building a forecast URL—the server needs latitude and longitude to know which place to model. In another thread the same syntax carries utm_source and utm_campaign; the page still loads, because many servers ignore keys they do not use, while analytics tools use those tags to trace where traffic came from.

Building URLs by hand is how you accidentally break spaces and & inside values; urllib.parse.urlencode and requestsparams keep the encoding honest. Same syntax, two roles—API contract versus marketing breadcrumb—and telling them apart is part of reading the web like an engineer.

Background: [1], Python urllib walkthrough [2].


Sources

University approvals: 0
Tasks
Question 1

In https://api.example.com/v1/forecast?latitude=47.3&longitude=8.5, what is the primary role of latitude and longitude in the query string?

Hint

Think about what the server needs to compute a location-specific response.

Question 2

A landing page URL contains ?utm_source=newsletter&utm_campaign=spring. What is the typical purpose of utm_* parameters?

Hint

UTM is widely used in digital marketing dashboards.

Question 3

Implement count_utm_keys(url: str) -> int counting distinct query parameter names whose lowercase form starts with utm_. Use urllib.parse.urlparse and parse_qs.

Example: https://shop.example/p?utm_source=x&utm_medium=y&id=12.

Submit the function; expression mode tests call it.

Hint

parse_qs returns a dict mapping each name to a list of values.

Starter code is prefilled; replace TODO blocks with your solution.
2 test cases will be used for grading
Run checks runtime behavior only. Final correctness is evaluated when you submit.
Card Info
  • Topic: Data Science Praktikum
  • Difficulty: Beginner
  • Completed: 1 users
Creator
Pavel
Pavel