#!/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. def main(): print("Find the reference angle of a given degree", "\nType only 'Enter' to quit") while True: degree = get_float("Degree? ") degree = return_positive(degree) quad = in_quad(degree) print_ref(degree, quad) def get_float(msg): while True: i = input(msg) try: if i: return float(i) else: exit() except ValueError as err: print(err) continue def return_positive(degree): if degree <= 360 and degree >=0: return degree while degree > 360: degree -= 360 if degree < 360 and degree >= 0: return degree while degree < 360: degree += 360 if degree < 360 and degree >= 0: return degree def in_quad(degree): if degree <= 90: return "I" elif degree <= 180 and degree > 90: return "II" elif degree <= 270 and degree > 180: return "III" elif degree <= 360 and degree > 270: return "IV" def print_ref(degree, quad): if quad == "I": ref = degree elif quad == "II": ref = 180 - degree elif quad == "III": ref = degree - 180 elif quad == "IV": ref = 360 - degree print("Reference angle is: {0}\N{DEGREE SIGN}".format(ref)) if __name__ == "__main__": main()