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

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0

    New to programming, completely lost.


    Hi

    Im new to python and programming in general, and I was given an assignment and I really have no clue on how to go about solving it.

    Part 1) Write a program that accepts the date as mon/day/yr and validates it as a real date. ( 5/1/12 is a real date, but something like 2/31/12 is not) Then on top of that figure out what day of the year it is out of 365.

    2)Write a program that computes the fuel efficiency of a multi-leg journey. The program will first prompt for the starting odometer reading and then get information about a series of legs. For each leg, the user enters the current odometer reading and the amount of gas used (separated by a comma). The program should print out the miles per gallon achieved on each leg and the total MPG for the trip, when the program is ended by a blank line

    3)Modify the MPG program to get its input from a file.

    If anyone could point me in the right direction it would be greatly appreciated, Im not looking for the answers or anything but just some assistance.
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2005
    Posts
    588
    Rep Power
    64
    Which version of Python are you going to use?
    Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by Dietrich
    Which version of Python are you going to use?
    Python 2.7, this was what the teacher preferred
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,709
    Rep Power
    480
    raw_input('prompt string')

    reads from the keyboard and returns a string in python 2.


    string.split might help, for example

    >>> 'this:that:the other thing'.split(':')
    ['this', 'that', 'the other thing']


    Conversion from string to number?

    >>> 12*int('4')
    48
    >>> 10*float('2.718')
    27.18

    I'd look for a calendar program to figure out which day of the year it is. Study the datetime module.


    Open a file:

    with open('trip.log','r') as inf:
    #use inf.readlines()


    Or is the structure of a program the stumbling block, rather than these details?
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo