I am an undergraduate statistics major attempting to learn some programming on the side. I purchased a python book and am stuck on a problem.
The chapter introduces For Loops and the preceding introduced functions.
Question - Write a program disttable.py that prints a table of mile to kilometer conversions for distances between 100 and 1500 miles at 100 mile intervals. Write a function to do the conversion. One mile approximately 1.609 km.
My code thus far -
def mile(x):
return 1.609 * x
def main():
for n in range(100,100,1501):
print(n,miles(n))
When I call main(), nothing happens. No error message.
I tried to place the for loop inside main(), however, I am unsure how to define the local variable inside the main() when I move the for loop there, so I end up getting a error message stating the local variable isn't defined.