0
0
Intro to Computingfundamentals~10 mins

IP addresses and domain names 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 print the IP address of a website using Python's socket module.

Intro to Computing
import socket
ip = socket.gethostbyname([1])
print(ip)
Drag options to blanks, or click blank then click option'
Alocalhost
Bexample.com
C"localhost"
D"example.com"
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting to put quotes around the domain name string.
Using a variable name without defining it.
2fill in blank
medium

Complete the code to split an IP address string into its four parts.

Intro to Computing
ip = "192.168.1.1"
parts = ip.[1](".")
print(parts)
Drag options to blanks, or click blank then click option'
Asplit
Breplace
Cjoin
Dfind
Attempts:
3 left
💡 Hint
Common Mistakes
Using join which combines strings instead of splitting.
Using replace which changes characters but does not split.
3fill in blank
hard

Fix the error in the code that checks if an IP address is valid by counting its parts.

Intro to Computing
ip = "10.0.0.256"
parts = ip.split(".")
if len(parts) [1] 4:
    print("Valid IP")
else:
    print("Invalid IP")
Drag options to blanks, or click blank then click option'
A==
B!=
C=
D<
Attempts:
3 left
💡 Hint
Common Mistakes
Using = instead of == causes syntax errors.
Using != reverses the logic.
4fill in blank
hard

Fill both blanks to create a dictionary mapping domain names to their IP addresses.

Intro to Computing
import socket

domains = ["example.com", "localhost"]
ip_map = {domain: [1] for domain in domains if domain [2] "localhost"}
print(ip_map)
Drag options to blanks, or click blank then click option'
Asocket.gethostbyname(domain)
B==
C!=
Ddomain
Attempts:
3 left
💡 Hint
Common Mistakes
Using == instead of != changes the filter logic.
Not calling the function to get IP addresses.
5fill in blank
hard

Fill all three blanks to create a list of IP addresses from a list of domain names.

Intro to Computing
import socket

domains = ["example.com", "localhost", "openai.com"]
ips = [[1] for [2] in domains if [3] != "localhost"]
print(ips)
Drag options to blanks, or click blank then click option'
Asocket.gethostbyname(domain)
Bdomain
Dsocket.gethostbyname(dom)
Attempts:
3 left
💡 Hint
Common Mistakes
Using different variable names inconsistently.
Calling the function with wrong variable names.