Command Palette

Search for a command to run...

Hectal
Phase 5: Functions
Python · Exercise 4 of 6 PreviousNext
Intermediate

Make options keyword-only

Write connect(host, *, port=80, secure=False) that returns the text http:// + host + : + port, for example http://a.com:80. When secure is true it starts with https:// instead.

The starter has no * yet. Add it, as shown, so that port and secure must be named in a call. Then connect("a.com", 8080) must raise TypeError.

What Check tests

  1. connect("a.com") returns http://a.com:80
  2. Keywords work
  3. A positional port raises TypeError
  4. A positional secure flag raises TypeError
  5. The host can still be a keyword

Stuck? One hint at a time

The solution unlocks after your first Check. Try first: that is where the learning happens.

main.py
Sign in to run your code.

Output

Press Run to see what your program prints.