Jan-28-2018, 04:38 AM
import math operation = (" ") result = 0.0 number1 = 0.0 number2 = 0.0 def choice(): global operation, number1, number2 choices = input('Enter in desired option then numbers:') operation, number1, number2 = choices.split(" ") return (operation, number1, number2) def add(): global result result = float(number1) + float(number2) return result def sub(): global result result = float(number1) - float(number2) return result def mul(): global result result = float(number1) * float(number2) return result def div(): global result result = float(number1) / float(number2) return result def absolute(): global result result = abs(float(number1)) return result def report(): print(result) def main(): print ('Welcome to homeBrewCalculator') print ('operations available are below:') print ('(add)ition') print ('(sub)traction') print ('(mul)tiplication') print ('(div)ivsion') print ('(absolute) value') print ('quit') done = False while not done: choice() if operation == 'add': add() report() elif operation == 'sub': sub() report() elif operation == 'mul': mul() report() elif operation == 'div': div() report() elif operation == 'abs': absolute() report() elif operation == 'quit': break main()I have to build a simple calculator that needs to read the command as a single line then it splits it up.
but i also have to have a quit function but when I try and quit I get this error below.
builtins.ValueError: not enough values to unpack (expected 3, got 1)
also when the program quits it is supposed to print function usage statistics and end the program of course. But I am stuck on how to integrate how many times a function has been used before the user quits.
it should look something like this when it quits
Function usage count
add function: 1
sub function: 0
mul function: 2
div function: 0
abs function: 3
depending how many times the user used each function before quitting.