#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0

    Assistance with basic Python programs


    Hello guys! I'm trying to learn the basics of Python and am doing some exercise questions I have found online. I stumbled upon a question that I can't seem to understand how to do. I am not asking you to do the question for me, I just need some help on how to do it. However, if you love programming so much that you want to help me by making the code, feel free to do so. Any help is appreciated! ***NOTE: I HAVE TO USE LOOPS***

    Your parents need to buy a new vehicle and they are trying to decide whether to purchase a hybrid or not. Hybrid vehicles
    produce less CO2 emissions and have better fuel efficiency
    compared to their non-hybrid counterpart. However, hybrid
    vehicles also cost a lot more money than their non-hybrid version.
    Help your parents make a decision as to which type of vehicle to buy (strictly in terms of the financial cost and not taking into account the environmental
    benefits). The typical family drives 20,000 kms each year and gas currently costs $1.30/litre.

    Allow the user to enter the cost of the hybrid and non-hybrid vehicle along with the combined fuel efficiency of those vehicles. Also, allow the user to enter the average amount
    of kilometers they drive each year (note: the average is 20000 km/year). Then output how many years of ownership it will take for the two cars to equal in cost. Assume that the price
    of gas stays the same at $1.30/litre.

    Obviously, the cost of gas will increase each year (this is called inflation). Perform
    the same calculation for a level 3, but incorporate into your calculation the idea that gas
    prices will rise by 3% each year (i.e. annual inflation rate is 3%).
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,701
    Rep Power
    480
    I'd write a main program.
    Code:
    def main():
        (km_per_L, km_per_year, cost_per_L, etceteras) = acquire_data()
        time_of_intersection = solve(a bunch of variables)
        report(time_of_intersection, and other variables)
    Then I'd set up a dummy acquire data to insert test data, or put the input into a file so that I redirect input. Thus I wouldn't need to retype the inputs as I try my solver.

    Next I'd search the internet for algorithms to solve systems of nonlinear equations. The non-linear solver will work for the linear case as well.
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    6
    Rep Power
    0
    The exercise states I am only allowed to use loops and such. I can't go ahead so I am not allowed to use def etc.

IMN logo majestic logo threadwatch logo seochat tools logo