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 can use a lookup table to store the different functions</p>

<pre><code>num=10
x=str(input("Enter Math Operation (+, -, *): "))
while (x != "+" and x != "-" and x != "*"):
    x=str(input("\tEnter Math Operation: "))
ops = {
    '+': lambda x, y: x+y,
    '-': lambda x, y: x-y,
    '*': lambda x, y: x*y}

fn = ops[x]
for table in range(1,11):
    print(str(num),str(x),table,"=",fn(num,table))
</code></pre>

python python-3.x