Divmod Function in Python

Level 120 keystrokes

This uses divmod() to get both quotient and remainder at once.

Python code

# divmod(a, b) returns the tuple (a // b, a % b): quotient and remainder
# 17 ÷ 5 is 3 with remainder 2, so (3, 2) is printed
1print(divmod(17, 5))

Output

(3, 2)
Practice typing this code

Practice typing this code. Results are not recorded in the rankings.

Symbols in this code

The symbols you type in this Python code and how often they appear.

  • (× 2
  • )× 2
  • ,× 1

More Python examples at level 1

← Python typing practice