0
0
Intro to Computingfundamentals~10 mins

URLs and their structure in Intro to Computing - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to extract the protocol from the URL string.

Intro to Computing
url = "https://example.com"
protocol = url.split('[1]')[0]
Drag options to blanks, or click blank then click option'
A/
B//
C:
D://
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' instead of '://', which misses the colon.
Using ':' alone, which splits too early.
2fill in blank
medium

Complete the code to get the domain name from the URL.

Intro to Computing
url = "https://example.com/path"
domain = url.split('[1]')[1].split('/')[0]
Drag options to blanks, or click blank then click option'
A//
B://
C:
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Splitting by '://', which includes the colon and may cause index errors.
Splitting by '/' first, which splits too early.
3fill in blank
hard

Complete the code to correctly extract the path from the URL.

Intro to Computing
url = "https://example.com/path/to/page"
path = url.split('//')[1].split('[1]', 1)[1]
Drag options to blanks, or click blank then click option'
A//
B://
C/
D:
Attempts:
3 left
💡 Hint
Common Mistakes
Splitting by '://' or '//' which does not isolate the path correctly after the domain.
Splitting by ':' which is unrelated to path separation.
4fill in blank
hard

Fill both blanks to create a dictionary mapping URL parts to their values.

Intro to Computing
url = "https://example.com:8080/path?query=1"
parts = {
  'protocol': url.split('[1]')[0],
  'port': url.split(':')[[2]].split('/')[0]
}
Drag options to blanks, or click blank then click option'
A://
B1
C2
D//
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' instead of '://', which misses the colon.
Using index 1 for port, which gets the domain instead.
5fill in blank
hard

Fill all three blanks to extract query parameters as a dictionary.

Intro to Computing
url = "https://example.com/path?user=alice&age=30"
query_string = url.split('[1]')[1]
params = {param.split('[2]')[0]: param.split('[2]')[1] for param in query_string.split('[3]')}
Drag options to blanks, or click blank then click option'
A?
B=
C&
D#
Attempts:
3 left
💡 Hint
Common Mistakes
Using '#' instead of '?', which is for fragments.
Using ':' or other symbols instead of '=' or '&'.