Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64273
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2014-01-18 18:23 -0800 |
| Message-ID | <4ea55e83-cfcd-4aaf-824a-3e3bced921c2@googlegroups.com> (permalink) |
| Subject | Help with simple code that has database defined |
| From | indar kumar <indarkumar59@gmail.com> |
I have to save students information in a database that is keeping continuously track of the information. Format is as follows:
Information: <name> <course> <grade> <duration>
Note: if this name already exists there in database, just update the information of that(name) e.g course,grade and date. Otherwise, add it.
What I think:
Database={} #First Created a dictionary that will keep track
z = "Enter student name, course, grade and duration: "
line = raw_input(z)
while (line != "quit"):
data = line.split()
name = data[0]
line = raw_input(z)
This is just part because this is what I know how to do, for rest have no idea
The output should be like this:
{'alex': ['7', '8', '6'], 'john': ['9', '8', '7']})
Now as program will continuously prompt for input. If user enters “quit” it would exit. Otherwise it keeps taking input.
Now if there is already a name existing for example “alex” and his course, grade and duration are 7,8,6. Now in next turn of input if user again enters the name as alex but different entries for him e.g 9,9,9 so it should replace the older info by new e.g. it should replace 7,8,6 for alex by 9,9,9 and if user enters a entirely new name that is not in dictionary then it should be added to dictionary for example nancy 6 6 6 is the input then output should be:
{'alex': ['7', '8', '6'], 'john': ['9', '8', '7'],’nancy’:[‘6’,’6’,’6’]})
Kindly help.
Back to comp.lang.python | Previous | Next — Next in thread | Find similar | Unroll thread
Help with simple code that has database defined indar kumar <indarkumar59@gmail.com> - 2014-01-18 18:23 -0800 Re: Help with simple code that has database defined Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-01-18 23:14 -0500 Re: Help with simple code that has database defined Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-19 20:05 +0000
csiph-web