| | |
Pay system
Please support our Python advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
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.
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.
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
python Syntax (Toggle Plain Text)
def ID_search(prod_id): infile=open("tab.txt","r") line=infile.readline() while line!="": x=string.split((line),",") if prod_id==float(x[0]): print "Product is", x[1] line=infile.readline() infile.close()
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
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?
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?
python Syntax (Toggle Plain Text)
def ID_search(prod_id): infile=open("tab.txt","r") line=infile.readline() while line!="": x=string.split((line),",") if prod_id==float(x[0]): print "Product is", x[1] line=infile.readline() 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
Theist: It's okay, can you imagine anything else that doesn't exist?
Junior MD --- Python, C++ and PHP
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
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.
Or just tell me how to start please
Here's an example of reading the file into a dictionary:
python Syntax (Toggle Plain Text)
def load_IDs(): infile=open("tab.txt","r") lines=infile.readlines() infile.close() my_IDs = {} for line in lines: data=line.strip().split(",") my_IDs[ data[ 0 ] ] = data[ 1 ] return my_IDs
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
Here's an example of reading the file into a dictionary:
python Syntax (Toggle Plain Text)
def load_IDs(): infile=open("tab.txt","r") lines=infile.readlines() infile.close() my_IDs = {} for line in lines: data=line.strip().split(",") my_IDs[ data[ 0 ] ] = data[ 1 ] return my_IDs
Can i work directly from the file?
You're reading the contents of the file into a dictionary, not a list.
What do you mean work directly from the file?
What do you mean work directly from the file?
•
•
Join Date: Sep 2008
Posts: 12
Reputation:
Solved Threads: 0
•
•
•
•
You're reading the contents of the file into a dictionary, not a list.
What do you mean work directly from the file?
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.
![]() |
Similar Threads
- Questions about building a system (was: newbie) (Troubleshooting Dead Machines)
- How do you do a full system reconfiguration on a dell 4600? PLEASE HELP! (Windows NT / 2000 / XP)
- Need to find Payment System for Overseas (eCommerce)
- Power Supply for High Power System (Cases, Fans and Power Supplies)
- Future system (Troubleshooting Dead Machines)
- System security software on XP (Viruses, Spyware and other Nasties)
- System CPU overusage (Windows NT / 2000 / XP)
- *Random System Restarts* (Win XP) (Windows NT / 2000 / XP)
- Removing ISLE.exe (Windows NT / 2000 / XP)
Other Threads in the Python Forum
- Previous Thread: Why doesnt my calculator script work! <----newb alert
- Next Thread: Approximation of Pi (Python)
| Thread Tools | Search this Thread |
accessdenied apache application argv array beginner book builtin change color converter countpasswordentry curved dan08 dictionary dynamic edit enter examples file filename float format function gui homework import inches input java keyboard lapse library line lines linux list lists loop microphone mouse movingimageswithpygame mysql mysqlquery newb number numbers numeric output parameters parsing path phonebook plugin port prime programming projects py2exe pygame pyopengl pysimplewizard python random recursion redirect remote reverse scrolledtext session simple smtp software sprite statictext string strings syntax table tennis terminal text textarea thread threading time tkinter tlapse trick tuple tutorial ubuntu unicode unit urllib urllib2 variable windows wordgame wxpython






