Order Now  +1 678 648 4277 

Conversion Function Assignment Solution using Python

The goal of this assignment is to give you some experience working with functions in Python. The program should display a menu with a list of conversions/calculations the program offers. The program should ask the user for a calculation choice, data required for the calculation, perform the calculation, and display the results. The program should allow the user to perform multiple calculations and exit when they are finished using the program. The program should offer at least 10 different conversions/calculations. Some of the calculations must require multiple inputs; you cannot have every calculation require a single input. You must create and use functions for every calculation/conversion and you must write the functions properly to accept inputs and return the result; your conversion/calculation functions should not get input from the user nor should they deliver the results to the screen.

The program should also create a text log file with all the calculations that were performed by the program. The log file should contain the date, time, operation, inputs, and results. Each line in the log file should represent one calculation that was performed. Make sure to label all values written to the log file, so that someone reading the log file would understand it.

Example Program:

*** Welcome to the CIS123 Conversion/Calculation Program ***

Conversions Menu:

  1. Miles to Kilometers
  2. Fahrenheit to Celsius
  3. Calculate the volume of a cylinder
  4. ..............
  5. Exit Program


Enter a choice for the conversion to perform: 1

Enter the miles: 100

Conversion results: 160.9 kilometers


Enter a choice for the conversion to perform: 11

Thanks for using the conversion program. Goodbye for now.


import math import datetime def MiltoKm(Mil): return 1.60934*Mil def KmtoMil(Km): return 0.621371*Km def FartoCel(Far): return (Far - 32)*5/9 def CeltoFar(Cel): return (Cel*9/5) + 32 def Kgtoton(Kg): return 0.00110231*Kg def tontoKg(ton): return ton*907.185 def RadtoDeg(rad): return rad*180/math.pi def DegtoRad(deg): return deg*math.pi/180 def VolofCylinder(r, h): return math.pi*r*r*h def AreaofCircle(r): return math.pi*r*r def main(): file = open("log.txt", "w") print("*** Welcome to the CIS123 Conversion/Calculation Program ***") print("Conversions Menu:") print("1.) Miles to Kilometers") print("2.) Kilometers to Miles") print("3.) Fahrenheit to Celsius") print("4.) Celsius to Fahrenheit") print("5.) Kilogram to ton") print("6.) ton to Kilogram") print("7.) Radians to Degree") print("8.) Degree to Radian") print("9.) Calculate volume of a cylinder") print("10.) Calculate area of a circle") print("11.) Exit Program") while True: print("-----------------------------------------------") usr_inp = input("Enter a choice for the conversion to perform: ") if usr_inp == "1": Mil = float(input("Enter the Miles: ")) Km = MiltoKm(Mil) print(f"Conversion Result: {Km} Kilometers") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Miles to Kilometers {Mil} Miles {Km} Kilometers\n") elif usr_inp == "2": Km = float(input("Enter the Kilometers: ")) Mil = KmtoMil(Km) print(f"Conversion Result: {Mil} Miles") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Kilometers to Miles {Km} Kilometers {Mil} Miles\n") elif usr_inp == "3": Far = float(input("Enter the Temperature in Farenheit: ")) Cel = FartoCel(Far) print(f"Conversion Result: {Cel} Celsius") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Farenheight to Celsius {Far} F {Cel} °C\n") elif usr_inp == "4": Cel = float(input("Enter the Temperature in Celsius: ")) Far = CeltoFar(Cel) print(f"Conversion Result: {Far} Farenheit") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Celsius to Farenheight {Cel} °C to {Far} F\n") elif usr_inp == "5": Kg = float(input("Enter the Kilograms: ")) ton = Kgtoton(Kg) print(f"Conversion Result: {ton} Ton") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Kilogram to ton {Kg} Kg to {ton} Ton\n") elif usr_inp == "6": ton = float(input("Enter the Tons: ")) Kg = tontoKg(ton) print(f"Conversion Result: {Kg} Kilograms") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Ton to Kilogram {ton} Ton to {Kg} Kg\n") elif usr_inp == "7": rad = float(input("Enter the Radians: ")) deg = RadtoDeg(rad) print(f"Conversion Result: {deg} Degrees") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Radians to Degree {rad} Rad to {deg} Deg\n") elif usr_inp == "8": deg = float(input("Enter the Degrees: ")) rad = DegtoRad(deg) print(f"Conversion Result: {rad} Radians") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} Degree to Radian {deg} Deg to {rad} Rad\n") elif usr_inp == "9": r = float(input("Enter the radius of Cylinder in m: ")) h = float(input("Enter the height of Cylinder in m: ")) Vol = VolofCylinder(r,h) print(f"Conversion Result: {Vol} m^3") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} radius {r} height {h} Volume of Cylinder {Vol} \n") elif usr_inp == "10": r = float(input("Enter the radius of Circle in m:")) area = AreaofCircle(r) print(f"Conversion Result: {area} m^2") ts = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") file.write(f"{ts} radius {r} Area of Circle {area} \n") elif usr_inp == "11": print("Thanks for using the conversion program. Good bye for now.") break file.close() main()