Stretch, Networking
Hosts in a subnet
The task
Given an IPv4 prefix length from 1 to 30, return how many usable host addresses the subnet has: 2 to the power of (32 − prefix), minus 2.
Write a function called usable_hosts.
Tests
| Call | Expected | Yours |
|---|---|---|
usable_hosts(24) |
254 |
not run |
usable_hosts(26) |
62 |
not run |
usable_hosts(30) |
2 |
not run |
usable_hosts(20) |
4094 |
not run |
usable_hosts(16) |
65534 |
not run |
solution.py
Tab indents. To leave the editor, press Escape, then Tab.
Output
Run prints what your code prints. Run the tests to check your function.