Help with simple code that has database defined


I

indar kumar

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 shouldreplace 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 itshould 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.
 
Ad

Advertisements

D

Dennis Lee Bieber

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>

This is your third request in 24 hours... You've gone from a
description of just simple one-line inputs to produce a simple GPA output
up to something with persistence (meaning you need to have a data file of
some sort between invocations of the program), and additional data fields.
Kindly help.

As you've been told, we do NOT do homework assignments (and if this is
NOT a homework assignment but an actual application for keeping student
grades for some school I strongly recommend you give them back whatever
money they paid you).

Ask a question about some aspect of Python that may not be understood,
and we'll give you an answer. "I need a program that does xyz, help!" will
not produce any results -- that's your job to do.
 
Ad

Advertisements

D

Denis McMahon

I have to save students information in a database that is keeping
continuously track of the information. Format is as follows:

You probably need to use one of the database modules.
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.

That sounds like an sql issue specific to your chosen database, not a
python issue.
This is just part because this is what I know how to do, for rest have
no idea

I suggest you get idea fast. Or ask your lecturers for advice. Or return
the advance you were paid on this coding job, because you don't seem to
have the skills to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top