Implementing a simple calculator in Python from pseudocode