### Thread: New to programming, completely lost.

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. Which version of Python are you going to use?
3. 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
4. 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: