I have to write a program that converts user entered Kilometers into Miles. But, I need to use two functions in addition to main program which is...

def main():
    print "This program converts distances measured in kilometers to miles."
    kilometers = input("What is the distance in kilometers?")
    miles = kilometers * .62
    print "The distance in miles is", miles
main()

The first function should ask for the kilometers driven and return them to the main program. The second function should receive the kilometers driven from the main program, calculate the miles driven and display them.
This is what I have, but I don't think it's right with the specifications. I need some help!

def kilo():
#variable name      type        purpose
#kilometers         float       distance in kilometers
    kilometers = input("What is the distance in kilometers?:")
    return kilometers
def miles():
#variable name      type        purpose
#miles              float       calculate distance in miles
    miles = kilo() * .62
    return miles
def main():
    print "This program converts distances measured in kilometers to miles."
    print miles()
main()

You mean something like this ...

def kilo():
    kilometers = input("What is the distance in kilometers?:")
    return kilometers
 
def miles(km):
    """calculates miles from kilometers km"""
    miles = km * .62
    return miles
 
def main():
    print "This program converts kilometers to miles."
    km = kilo()
    print miles(km)
 
main()

Beautiful. That greatly helps me out.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.