I would like to place operators as a list and then call an element from the list to use as an operator.
If I don't place quotations around the operators, then I get a syntax error for the commas inside of the list:
File "p22.py", line 24
cat = [+,-,*]
^
SyntaxError: invalid syntax
If I do place the quotations around, then I seem to lost the operator's function, as seen in this instance:
File "p22.py", line 30
a = (x which y)
^
SyntaxError: invalid syntax
Here is the full code:
import random
def start():
print('\n________________________________________')
print('| |')
print('| Zach\'s Tutorifier! |')
print('| |')
print('| |')
print('| Instructions: |')
print('| Select the type of math you want |')
print('| to practice with: |')
print('| 1-Add 2-Subtract 3-Multiply |')
print('|--------------------------------------|')
start()
math = int(input('> ')) - 1
cat = ['+','-','*']
def problems():
which = cat[math]
x = random.randint(0,9)
y = random.randint(0,9)
a = (x which y)
print('What is %i %s %i?' % (x, which, y) )
answer = input('> ')
if answer == a:
print('Congratulations! Try again? (Y/N)')
again = input('> ')
if again == 'Y' or again == 'y':
problems()
else:
start()
else:
print('Try again!')
problems()