Hello again everyone. I am creating a math game sort of...I dont know if they call it a case or switch statement but I want one in both my Menus. Also I am wondering if you can create an if statement or case statement that will support two variables...for example: if a == 2 and b == 3...THanks for your help and please respond as quick as possible...

by the way here is my code I would like you to fix with case statements:

``````import random
print("""Difficulties:
1.) - Easy
2.) - Medium
3.) - Hard""")
return int(raw_input("Choose a difficulty"))

print("""Types of Math:
2.) - Subtract
3.) - Divide
4.) - Multiply""")
return int(raw_input("Choose one of the choices"))
def main():
main()
``````

Usually is to have sequence of values or dictionary, functions if necessary

``````from __future__ import division
from operator import *

case_func = [('+', add), ('-', sub), ('/', truediv), ('*', mul)]

print("""Types of Math:
2.) - Subtract
3.) - Divide
4.) - Multiply""") …``````

## All 4 Replies

Usually is to have sequence of values or dictionary, functions if necessary

``````from __future__ import division
from operator import *

case_func = [('+', add), ('-', sub), ('/', truediv), ('*', mul)]

print("""Types of Math:
2.) - Subtract
3.) - Divide
4.) - Multiply""")
return int(raw_input("Choose one of the choices. "))-1

print '3 %s 4 = %s' % (case_func[selection], case_func[selection](3,4))
``````

``````import random

print("""Difficulties:
1.) - Easy
2.) - Medium
3.) - Hard""")
return int(raw_input("Choose a difficulty: "))

print("""Types of Math:
2.) - Subtract
3.) - Divide
4.) - Multiply""")
return int(raw_input("Choose one of the choices:"))

def pick_random_integer(difficulty):
# replace multiple if/else with dictionary
return {
1 : random.randrange(1, 10),
2 : random.randrange(10, 100),
3 : random.randrange(100, 1000)
}.get(difficulty)

def main():