Can someone tell me whats wrong with my python file? # # # # Global constant for conversion KILOMETERS_TO_MILES = 0.6214 # main def def main() # Local variables mykilomaters = 0.0 # Variable to hold the distance in kilometers # Get distance in kilometers mykilometers = float(input("Enter the distance in kilometers: ")) # Print miles showMiles(mykilometers) # The showMiles function accepts kilometers as an argument # and prints
Ok so i got most of it I think but i need help wit the last part
You have probably programmed in Java or C++ before. In Python, the indent replaces the braces, which means that indenting rules are very strict. The "main()" is not required in Python. If it's not in a function, it's in main. Unlike Java or C, there is no need to declare a variable before use. Also, formatting in Python is different from printf in Java or C. For documentation, you can try: https://docs.python.org/3/library/string.html or unless you have to print exactly 2 decimal digits, you can print print(".....", miles, " miles");
yeah but thats not the problem. its something else. I just dont know what i have to do lol
Do you have a compilation problem or execution problem? You said you know you have problems with indent, format, etc. There is also a problem of you calling main and the global variables are interrupted by the definition of the functions. You need to put them together, and possibly near the end, similar to compiling c programs. Can you fix them up and run to see what's left? The program runs properly when all of the above are fixed.
Join our real-time social learning platform and learn together with your friends!