A repository for the git good Redbrick workshop.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
1.4 KiB

  1. #################################
  2. # CALCULATOR FUNCTIONS
  3. ################################
  4. def add(x, y):
  5. pass
  6. def sub(x, y):
  7. pass
  8. def mul(x, y):
  9. pass
  10. def div(x, y):
  11. pass
  12. def mod(x, y):
  13. pass
  14. def exp(x, y):
  15. pass
  16. #################################
  17. # RUN CALCULATOR & MAIN FUNCTIONS
  18. #################################
  19. # DONT CHANGE THIS CODE
  20. def run_calculator(line):
  21. # set command as first word passed to the program
  22. command = line[0]
  23. # run until command is exit
  24. """
  25. while command != "exit":
  26. # check that line is of format - `command x y`
  27. if len(line) > 3 or len(line) == 1:
  28. # tell user error occured and end program
  29. print("Error in number of arguments supplied!")
  30. break
  31. else:
  32. # set values of x and y
  33. x, y = int(line[1]), int(line[2])
  34. # get name of command passed by the user as a function
  35. func = globals()[command]
  36. # run command with x and y as parameters and print result
  37. print(func(x, y))
  38. # read in next lien of input and split on whitespace
  39. line = input().split(" ")
  40. # set new command
  41. command = line[0]
  42. """
  43. def main():
  44. # split input on whitespace
  45. line = input().split(" ")
  46. # run calculator with split line
  47. run_calculator(line)
  48. if __name__ == "__main__":
  49. main()