#!/usr/bin/python3 # Exercises 11-2 through 11-4 combined # Page 233 import temp_conv, sys if __name__ == "__main__": run_help = "Please run as c2f_mod.py [Temp] F or C" try: usr_temp = float(sys.argv[1]) usr_fc = sys.argv[2].lower() if usr_fc == 'f': print("{:2f}".format(temp_conv.f2c(usr_temp))) elif usr_fc == 'c': print(temp_conv.c2f(usr_temp)) else: raise AttributeError except ValueError: print("Invalid number for Temperature") print(run_help) except IndexError: print("Incorrect number of arguments") print(run_help) except TypeError: print("Temperature must be a number") print(run_help) except AttributeError: print("Temperature must be followed by F or C") print(run_help)
#!/usr/bin/env python from temp_conv import c2f temp_str = input("Enter Celsius temp: ") celsius = float(temp_str) fahrenheit = c2f(celsius) print("{:.1f} C is {:.1f} F".format(celsius, fahrenheit))
def testc2f(self): """test c2f function""" for c_temp, f_temp in zip(self.c_temperatures, self.f_temperatures): self.assertEqual(f_temp, tc.c2f(c_temp))