Arithmetic/Integer: Difference between revisions

(→‎{{header|Python}}: py3k variant)
Line 336:
 
(In general it's good practice to perform parsing of all input in exception handling blocks. This is especially true of interactive user input, but also applies to data read from configuration and other files, and marshaled from other processes via any IPC mechanism).
 
 
== Python 3.0 compatible code ==
<python>def arithmetic(x, y):
for op in '+ - // %'.split():
expr = "%(x)s %(op)s %(y)s" % vars()
print("%s\t=> %s" % (expr, eval(expr)))
 
 
arithmetic(12, 8)
arithmetic(input("Number 1: "), input("Number 2: "))</python>
Output:
<pre>12 + 8 => 20
12 - 8 => 4
12 // 8 => 1
12 % 8 => 4
Number 1: 20
Number 2: 4
20 + 4 => 24
20 - 4 => 16
20 // 4 => 5
20 % 4 => 0</pre>
 
=={{header|Raven}}==
A
59

edits