Integer comparison: Difference between revisions

(Factor)
Line 880:
(Note: in Python3 ''raw_input()'' will become ''input().'').
 
An alternative implementation could use a Python dictionary to house a small dispatch table to be indexed by the results of the buildbuilt-in ''cmp()'' function. ''cmp()'' returns a value suitable for use as a comparison function in a sorting algorithm: -1, 0 or 1 for <, = or > respectively. Thus we could use:
 
{{works with|Python|2.x}}
<lang Python>#!/usr/bin/env python
import sys
Line 899 ⟶ 900:
 
In this case the use of a dispatch table is silly. However, more generally in Python the use of dispatch dictionaries or tables is often preferable to long chains of '''''elif'''' clauses in a condition statement. Python's support of classes and functions (including currying, partial function support, and lambda expressions) as first class objects obviates the need for a "case" or "switch" statement.
 
=={{header|R}}==
<lang R>print("insert number a")
Anonymous user