I wrote this little guy a while ago. I'm brand new to DaniWeb, and happy to be here. This was one of the earlier things I wrote in Python, and therefore one of the earlier things I wrote period. I've since done some much more complicated nonsense, but this one always stuck with me. A word of warning, it is fairly depressing. Assuming that we're trying to even get to the next closest celestial body outside of our solar system (Proxima Centauri) and even giving us the advantage of a very very fast speculative speed (350,000mph (Earth's escape velocity is about 25,000mph)) it would still take 8047 years 145 days 20 hours 2 minutes and 14 seconds to travel there. Sigh, I guess we all better start recycling more.

Anyway, here's the program. Have at it. Let me know if there are any glaring errors, discrepancies, stupidities, or goofs that I have missed. Have the fun!

#!/usr/bin/env python
# cosmictrip.py
# A program to calculate the mileage of cosmic and terrestrial voyages
# written by aLT with much assistance from CJY 2008

def dest():
    print
    destination = raw_input("+ Where in the Universe would you like to travel? ")
    return destination

def body():
    destination = dest()
    scale = ""
    while(scale != "m" or scale != "l"):
        scale = raw_input("+ Is your destination reachable in miles or lightyears? ")
        if scale[0].lower() == "m":
            miles, speed = mileage()
            break
        elif scale[0].lower() == "l":
            miles, speed = lightyr()
            break
        else:
            print "Pick an acceptable answer please. "
    miles, years, days, hours, minutes, seconds = calculations(miles, speed)
    results(destination, miles, years, days, hours, minutes, seconds)

def calculations(miles, speed):
    years = miles / (speed * 8765.81277)
    days = (years - int(years)) * 365
    hours = (days - int(days)) * 24
    minutes = (hours - int(hours)) * 60
    seconds = (minutes - int(minutes)) * 60
    return miles, years, days, hours, minutes, seconds

def lightyr():
    ltYr = input("+ How many light years away is your destination? ")
    speed = input("+ How fast, in miles per hour, can your cosmic van travel? ") 
    miles = float(ltYr) * 5878499810000.0
    return miles, speed

def mileage():
    miles = input("+ How many miles away is your destination? ")
    speed = input("+ How fast, in miles per hour, can your cosmic van travel? ")
    return miles, speed

def results(destination, miles, years, days, hours, minutes, seconds):
    print "\n", destination.upper(), "is", int(miles), "miles away.\n"
    print "It would take you", int(years), "years", int(days), \
    "days", int(hours), "hours", int(minutes), "minutes and", \
    int(seconds), "seconds to travel to", destination.upper(), \
    "in your cosmic van, assuming the weather holds up.\n"
    if 10 <= years <= 60:
        print "You might be able to make it if you leave right now.\n"
    elif years <= 0.1:
        print "That's not a bad trip at all. You should go.\n"
    else:
        print "You probably wouldn't survive the trip.\n"

def main():
    print
    print "<<<------------------- UNIVERSAL TRIP PLANNER ------------------->>>".center(80)
    print "\nA program to tell you how many miles away and" \
    " how long it would take you to reach various destinations" \
    " in the cosmos."
    repeat = "y"
    while(repeat[0].lower() == "y"):
        body()
        repeat = raw_input("+ Would you like to travel to another location? ")
    print "\nKeep looking for wormholes.\n"
    print ">>-------------------------->>>: + :<<<--------------------------<<".center(80)
    print
    
if __name__ == '__main__':
    main()

A nice project! Welcome to the small group of DaniWeb Pythonoreans and Pythealots here.

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.