Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to print the main part of a web address.
Intro to Computing
url = 'https://www.example.com' main_part = url.split('[1]')[1] print(main_part)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '//' instead of '://' causes wrong splitting.
✗ Incorrect
The code splits the URL at '://', so the main part is after this.
2fill in blank
mediumComplete the code to check if a web address starts with 'https'.
Intro to Computing
url = 'https://secure.site' if url.[1]('https'): print('Secure connection')
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'contains' or 'find' does not check the start specifically.
✗ Incorrect
The startswith method checks if the string begins with the given text.
3fill in blank
hardFix the error in the code that extracts the domain name from a URL.
Intro to Computing
url = 'http://openai.com' domain = url.split('[1]')[1] print(domain)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Splitting by 'http://' causes the first part to be empty.
✗ Incorrect
Splitting by '://' correctly separates the protocol from the domain.
4fill in blank
hardComplete the code to create a dictionary of web pages and their status codes.
Intro to Computing
pages = ['home', 'about', 'contact'] status_codes = {page: 200 for page in pages if page [1] 'home'}
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using '=' instead of ':' in dictionary comprehension.
Using '==' instead of '!=' in the condition.
✗ Incorrect
The dictionary comprehension uses ':' to map keys to values and '!=' to filter out 'home'.
5fill in blank
hardFill all three blanks to filter and transform a list of URLs.
Intro to Computing
urls = ['http://site1.com', 'https://site2.com', 'ftp://site3.com'] secure_sites = [url[1] for url in urls if url.[2]('https') and url.[3]('.com')]
Drag options to blanks, or click blank then click option'
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong slice index.
Using 'contains' instead of 'startswith' or 'endswith'.
✗ Incorrect
We slice from index 8 to remove 'https://' prefix, check if URL starts with 'https', and ends with '.com'.