How can I condense a 'for x in range' statement within a 'if' 'elif' statement within a 'while' statement
<p>I have a code that makes a math table and I feel has the possibility to be reduced as I have three of the same codes repeated but with only slightly different solutions for each of the if/elif statements. </p>

<pre><code>num=10
x=str(input("Enter Math Operation (+, -, *): "))
while (x != "+" and x != "-" and x != "*"):
    x=str(input("\tEnter Math Operation: "))
    if x=="+":
        for table in range(1,11):
            print(str(num),str(x),table,"=",num+table) 
    elif x=="-":
       for table in range(1,11):
            print(str(num),str(x),table,"=",num-table) 
    elif x=="*":
       for table in range(1,11):
            print(str(num),str(x),table,"=",num*table)
</code></pre>

<p>Please tell me how this code can be condensed.</p>

<p>You would typically do something like this:</p>

<ul>
<li><p>Store the operator as a function in a variable</p></li>
<li><p>Use a dictionary to look up operators</p></li>
<li><p>Use <code>.format()</code> instead of putting lots of string pieces together</p></li>
<li><p>Don't use <code>str()</code> if the argument is already a string</p></li>
</ul>

<p>Here is what that looks like:</p>

<pre><code>import operator
x = 10
operators = {
    '+': operator.add,
    '-': operator.sub,
    '*': operator.mul,
}
while True:
    op_name = input('Enter Math Operation ({}): '.format(', '.join(operators)))
    op_func = operators.get(op_name)
    if op_func is not None:
        break
for y in range(1, 11):
    print('{} {} {} = {}'.format(x, op_name, y, op_func(x, y)))
</code></pre>

python python-3.x