In my senior year of high school, I decided to take a programming class (we use Python). I had been approached by multiple people who took programming in the past and told me that I should take it because it was useful for college and beyond. So far, it has been tough. We have a lot of homework most of the time, but I like to think that I have good time management skills, so it hasn’t been as hard as it could be. I am writing this when we are just over halfway through the class, because it’s only a semester long.
For this post, I decided to include my Distance Conversion program. Basically, this program allows the user to input a number of either miles or kilometers and the program will convert it to the other unit (miles to kilometers or kilometers to miles). It also gives a recommendation as to how the user should go that distance, whether it be walking, driving, flying, or something else. It doesn’t allow the user to input any negative numbers for their distance. The conversion options are numbered 1-2, and if the user doesn’t enter 1 or 2 for the conversion they want to do, the program will ask them to do it again.
I faced the most adversity with this program, as I had to learn how to do a lot of debugging techniques. One of the major problems was that instead of having kilometers as one of the units, the program was keeping it in miles. In order to solve this, I had to learn about “type debugging” where you enter something like type(23) or type(miles) and it will tell you whether it was an integer, string, float, or something else. I asked multiple people about my problem, and it took about an hour of debugging to figure it out. This was really frustrating at the time, but it was really satisfying to figure out and I will definitely use these new skills if I have similar problems in the future. If I would’ve had more time, I would have included some more conversions, like miles to nautical miles, kilometers, to nautical miles, and the opposites of those. However, being as it was volleyball season and I was already really busy, I didn’t have as much time as I wanted to make this program as best as it could be.
def main(): give_instructions() x = get_number() ask_conversion(x) repeat() cleanup()
def ask_conversion(x): """Asks the user which kind of conversion they would like to perform.""" print("==============================================================") print(" Conversion Options") print("==============================================================") print("1. Miles to Kilometers") print("2. Kilometers to Miles") answer = input("Which number of conversion would you like to perform? ") if answer == "1": convert_miles(x) elif answer == "2": convert_km(x) while answer.isalpha(): answer = input("*** You have to enter 1 or 2: ") if answer == "1": convert_miles(x) elif answer == "2": convert_km(x)