Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- commands = ["add","subtract","multiply","divide","power"]
- operators = ["+","-","*","/","**"]
- def mathquestion():
- instruction = input("What maths function would you like to perform? ").lower()
- operator = operators[commands.index(instruction)]
- first = int(input("Please type your first number: "))
- second = int(input("Please type your second number: "))
- expression = str(first)+operator+str(second)
- result = eval(expression)
- print(expression+" = "+str(result))
- finished = False
- while not finished:
- mathquestion()
- another = input("Another question? ")
- if another.lower()[0:1]=="n":
- finished = True
- print("OK, bye!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement