December 14th, 2012, 03:45 PM
New to programming, completely lost.
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.
December 14th, 2012, 04:24 PM
Which version of Python are you going to use?
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
December 14th, 2012, 04:30 PM
Python 2.7, this was what the teacher preferred
Originally Posted by Dietrich
December 14th, 2012, 05:16 PM
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?
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:
Or is the structure of a program the stumbling block, rather than these details?
[/code] are essential for python code and Makefiles!