0

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()
2
Contributors
2
Replies
12
Views
10 Years
Discussion Span
Last Post by mouigher
0

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()
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.