Pay system

Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Pay system

 
0
  #1
Nov 16th, 2008
Its about the pay system of a shop.
The user enters a product ID,the interpreter gets the details from the file and appends it to a list and continues till the products are over.

If the user can't enter the ID he can add the product name directly which will get the details from the file and append to list again.

From the list the total price will be displayed and the product names which will be in the file.

There must also be a fucntion to delete a product from the list and make new sum accordingly.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Re: Pay system

 
0
  #2
Nov 16th, 2008
  1. def ID_search(prod_id):
  2.  
  3. infile=open("tab.txt","r")
  4.  
  5. line=infile.readline()
  6.  
  7. while line!="":
  8. x=string.split((line),",")
  9. if prod_id==float(x[0]):
  10. print "Product is", x[1]
  11. line=infile.readline()
  12.  
  13. infile.close()
This is the function i've used for search the ID from the file and display result..Please need help from here on.

Editor's note:
Please use code tags with your code to preserve the indentations. Otherwise the code is very difficult to read and not too many folks will help.

[code=python]
your Python code here
[/code]
Last edited by vegaseat; Nov 17th, 2008 at 6:29 pm. Reason: added code tags
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,401
Reputation: evstevemd has a spectacular aura about evstevemd has a spectacular aura about evstevemd has a spectacular aura about 
Solved Threads: 128
evstevemd's Avatar
evstevemd evstevemd is offline Offline
Nearly a Posting Virtuoso

Re: Pay system

 
0
  #3
Nov 16th, 2008
Dear Feenix45,
The best way is to enclose the code in bracket to maintain the
Indentation which is vita important. Just wrap your code tags


Is this what you originally wrote??
Is your application GUI or Console?

  1. def ID_search(prod_id):
  2. infile=open("tab.txt","r")
  3. line=infile.readline()
  4. while line!="":
  5. x=string.split((line),",")
  6. if prod_id==float(x[0]):
  7. print "Product is", x[1]
  8. line=infile.readline()
  9. infile.close()
Last edited by evstevemd; Nov 16th, 2008 at 3:33 pm.
Atheist: God is man made imagination, he doesn't exist!
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
Reply With Quote Quick reply to this message  
Join Date: Dec 2006
Posts: 1,045
Reputation: woooee is a jewel in the rough woooee is a jewel in the rough woooee is a jewel in the rough 
Solved Threads: 294
woooee woooee is online now Online
Veteran Poster

Re: Pay system

 
0
  #4
Nov 16th, 2008
Also, you open the file and read the entire file for each ID entered. This is time consuming (in computer time) and so you should consider reading the file once and placing the records in a dictionary, indexed on ID, and using the dictionary to look up the info as it is entered.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Re: Pay system

 
0
  #5
Nov 17th, 2008
hmm its GUI but about dictionary never did this can u help me with the indexes and dictionary plz.
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Re: Pay system

 
0
  #6
Nov 18th, 2008
Originally Posted by woooee View Post
Also, you open the file and read the entire file for each ID entered. This is time consuming (in computer time) and so you should consider reading the file once and placing the records in a dictionary, indexed on ID, and using the dictionary to look up the info as it is entered.
Can u guide me with this please?

Or just tell me how to start please
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,062
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 267
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Pay system

 
0
  #7
Nov 18th, 2008
Here's an example of reading the file into a dictionary:
  1. def load_IDs():
  2. infile=open("tab.txt","r")
  3. lines=infile.readlines()
  4. infile.close()
  5. my_IDs = {}
  6. for line in lines:
  7. data=line.strip().split(",")
  8. my_IDs[ data[ 0 ] ] = data[ 1 ]
  9. return my_IDs
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Re: Pay system

 
0
  #8
Nov 18th, 2008
Originally Posted by jlm699 View Post
Here's an example of reading the file into a dictionary:
  1. def load_IDs():
  2. infile=open("tab.txt","r")
  3. lines=infile.readlines()
  4. infile.close()
  5. my_IDs = {}
  6. for line in lines:
  7. data=line.strip().split(",")
  8. my_IDs[ data[ 0 ] ] = data[ 1 ]
  9. return my_IDs
Thanx but this means i copy the file on a list.

Can i work directly from the file?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 1,062
Reputation: jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough jlm699 is a jewel in the rough 
Solved Threads: 267
Sponsor
jlm699's Avatar
jlm699 jlm699 is offline Offline
Knows where his Towel is

Re: Pay system

 
0
  #9
Nov 18th, 2008
You're reading the contents of the file into a dictionary, not a list.

What do you mean work directly from the file?
1. Use Code Tags.
2. Homework? Show Effort.
3. Keep discussions on the forum: no PMs
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 12
Reputation: Feenix45 is an unknown quantity at this point 
Solved Threads: 0
Feenix45 Feenix45 is offline Offline
Newbie Poster

Re: Pay system

 
0
  #10
Nov 18th, 2008
Originally Posted by jlm699 View Post
You're reading the contents of the file into a dictionary, not a list.

What do you mean work directly from the file?
No i dont know how to work with dictionary.

all the data are stored on a text file which im using though its a bit more time consuming.

Is there a way that i can do product search?i.e i enter the product name and it displays the price.
The program must search the price in the file.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Python Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC