#!/usr/bin/env python3 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, # MA 02110-1301, USA. ## modified get_int() for this program to print examples if 'enter' def get_int(msg, printd): while True: i = input(msg) try: if i: i = int(i) return(i) else: print(printd) break except ValueError as err: print(err) continue def remainder(exponent): r = (exponent / 4) - (exponent // 4) if r == 0.25: return 1 elif r == 0.5: return 2 elif r == 0.75: return 3 elif r == float(0): return 4 def print_simp(exponent, remainder): if remainder == 1: p = "i^1" a = "i" elif remainder == 2: p = "i^2" a = "-1" elif remainder == 3: p = "i^3" a = "-i" elif remainder == 4: p = "i^4" a = "1" print("i^{0} = {1} = {2}".format(exponent, p, a)) def main(): print("Simplify a complex number, type a number as the exponent, or 'enter' for examples. \nUse ^C to exit.") printd = "i^1 = i \ni^2 = -1 \ni^3 = -i \ni^4 = 1" while True: try: e = get_int("i\u207F ", printd) if e is not None: print_simp(e, remainder(e)) except KeyboardInterrupt: print() break if __name__ == "__main__": main()