Help with small python script

Soldato
Joined
17 Aug 2005
Posts
7,612
Location
Swindon
Hello all. I am trying to learn python and have been doing a few sites on and off like codingbat, lpthw, code academy etc.. and have decided to try and make something in an attempt to put some bits together. Plus doing so has meant I have been searching for answers and have come across some quite useful things in the process.

I am trying to create a kind of small expenditure thing which takes input from a user with the date and then under this date it gets the user to put a place of spend and then the amount, it will keep looping the last two things until the user has put in all the info for that date then they can either close or return to the menu. I would like to write this to the file defined. Originally I had this to write straight to the file but then I had problems getting it to format correctly so decided maybe the best way was with lists? Not sure if this is the best way of doing it but now for each place it writes to one list, for the amount it writes to another and then I want to combine these two on one line and write this to the file. Then for it to go back to asking for another place etc..etc..

In the end once I have done this correctly I want to be able to print the items in the file so the user can see each place and the amount under the date.

I hope that makes sense, this is probably miles away from being any where near correct. I seem to have made it worse as my original way seemed to work easier by just writing to the file after each place and amount was given.

Anyway here is what I have done so far

http://pastebin.com/K9PFcTd1

Don't expect people to complete it all for me just a few pointers of what I have done correct/haven't/what I can do and what I should do to make it neater/easier.

Thanks.
 
Soldato
OP
Joined
17 Aug 2005
Posts
7,612
Location
Swindon
Writing both to the same list would give me this though wouldn't it
item 1
item 1 cost
item 2
item 2 cost

Ideally I want it to go
Date
Item 1 item 1 cost
item 2 item 2 cost

I would like to be able at some stage for the user to amend an item by removing a line so by having the item # and item cost on same line it should make this easier in the future?
 
Soldato
OP
Joined
17 Aug 2005
Posts
7,612
Location
Swindon
Thanks for that geuben. I haven't got as far as dictionaries and tuples yet so that is above my head but it looks interesting and certainly an easier to do it. I was thinking of having to chop lists up with the separator thing and combining stuff all over the place.
 
Soldato
OP
Joined
17 Aug 2005
Posts
7,612
Location
Swindon
Thanks A.N.Other appreciate the time.
I have that dive into Python but haven't started on it yet as I was doing LPTHW and made it through a large portion of that.

That last bit if I get it right, is basically saying
with open file x:
do this

and then it automatically closes at the end? So no need to reopen and close each time. That point you make about taking you back to the start I think is where I had issues trying to correct it as I was getting an error. Not had chance to look at it last few days had other work to do but I shall crack on with it, kind of fun tinkering although frustrating when you aren't really sure. It has meant I have looked up bits though that I did not know before just have not incorporated them yet.
 
Back
Top Bottom