Sep-21-2022, 11:02 AM
import math def allString(first, second): operation = ('add', 'subtract', 'multiply', 'divide') for v in operation: print(f"you cannot {v} {first} to {second}") def getBoolean(first, second): operands = [] # converting this to upper so checking will be minimal if (first.upper() == 'TRUE'): operands.append(True) if (first.upper() == 'FALSE'): operands.append(False) if (second.upper() == 'TRUE'): operands.append(True) if (second.upper() == 'FALSE'): operands.append(False) return operands def evaluateBoolean(first, second): operands = getBoolean(first, second) if operands[0] and operands[1]: andValue = True else: andValue = False if operands[0] or operands[1]: orValue = True else: orValue = False print("\nSelection = G (Logical and)") print(f"{first} and {second} is {andValue}\n") print("Selection = H (Logical or)") print(f"{first} or {second} is {orValue}\n") def convertOperands(first_operand, second_operand): operands = [] operands.append(int(first_operand)) operands.append(int(second_operand)) return operands def evaluateExpression (first_operand, second_operand): operands = convertOperands(first_operand, second_operand) sum = operands[0] + operands[1] difference = operands[0] - operands[1] product = operands[0] * operands[1] quotient = operands[0] / operands[1] whole = math.floor(quotient) remain = operands[0] % operands[1] power = math.pow(operands[0], operands[1]) print("\nSelection = A (add)") print(f"The sum of {operands[0]} and {operands[1]} is: {sum}\n") print("Selection = B (subtract)") print(f"The difference between {operands[0]} and {operands[1]} is: {difference}\n") print("Selection = C (multiplicaton)") print(f"The product of {operands[0]} and {operands[1]} is: {product}\n") choice = input("Do you want to display decimals?: ") if (choice.upper() == 'YES' or 'Y'): print("\nSelection = D (division)") print(f"The complete quotient between {operands[0]} and {operands[1]} is: {quotient}\n") else: print("\nSelection = D (division)") print(f"The rounded quotient between {operands[0]} and {operands[1]} is: {whole}\n") print("Selection = E (Modulo)") print(f"The remainder of {operands[0]} divided by {operands[1]} is: {remain}\n") print("Selection = F (Exponent)") print(f"{operands[0]} raised to the power of {operands[1]} is: {power}\n") def checkInput(): user_input = input("Input: ") operands = user_input.split('&') if '"' in operands[0] or '"' in operands[1] or "'" in operands[0] or "'" in operands[1]: allString(operands[0], operands[1]) # detect if there are boolean inputs elif 'true' in operands[0] or 'false' in operands[0]: evaluateBoolean(operands[0], operands[1]) # if none of the above, we evaluate input as digits else: evaluateExpression(operands[0], operands[1]) checkInput()how do i change/add selection as an input??