Skip to content
ExamSpine

Lesson 4.3 · Write it

Double a number

A functionPython or Java6 tests, 3 of them hidden

On a phone? Put the lines in order instead

Write a function that returns twice the value of its input.

  1. n is a whole number from -1000 to 1000.
  2. Return n multiplied by 2.

Only the number your function returns is checked.

def double_value(n: int) -> int

Examples

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

  • double_value(3) should return 6: a small positive number (rule 2)
  • double_value(0) should return 0: zero doubled is zero (rule 2)
  • double_value(-4) should return -8: a negative number (rule 2)

public static int doubleValue(int n)

Checking whether Java answers can run here.

Examples

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

  • doubleValue(3) should return 6: a small positive number (rule 2)
  • doubleValue(0) should return 0: zero doubled is zero (rule 2)
  • doubleValue(-4) should return -8: a negative number (rule 2)
solution.pySolution.java