Skip to content
ExamSpine

Lesson 5.3 · Write it

Before the @

A functionPython or Java7 tests, 4 of them hidden

On a phone? Put the lines in order instead

Write a function that returns the part of an email address that comes before the @.

  1. The address contains exactly one @. Every other character is an English letter, a digit, a dot or a hyphen.
  2. There is at least one character before the @.
  3. Return every character before the @, and nothing else. The @ itself is not included.

Only the value your function returns is checked.

def username(address: str) -> str

Examples

Your function is tested on 7 cases: the 3 examples below, and 4 hidden ones that check the rules above.

  • username("mia@example.org") should return "mia": three characters before the @ (rule 3)
  • username("a@b.example") should return "a": one character before the @, the fewest allowed (rule 2)
  • username("sam.lee@example.net") should return "sam.lee": a dot before the @ is part of the answer

public static String username(String address)

Checking whether Java answers can run here.

Examples

Your function is tested on 7 cases: the 3 examples below, and 4 hidden ones that check the rules above.

  • username("mia@example.org") should return "mia": three characters before the @ (rule 3)
  • username("a@b.example") should return "a": one character before the @, the fewest allowed (rule 2)
  • username("sam.lee@example.net") should return "sam.lee": a dot before the @ is part of the answer
solution.pySolution.java