-1

Start a new Python script and write some suitable input commands to store three items of data into three variables: Student Name, Coursework Mark, and Exam Mark. The inputs for coursework mark and exam mark should be validated as a value in the range 0-100%.

  1. Add new student records
  2. Show all student records
  3. Delete a student record
  4. Dislay overall average coursework mark
  5. Display overall average exam mark
  6. Display all aggregate marks
  7. Display overall average aggregate mark
  8. Exit

I need to delete student records and a student name from the list but dont know how to this in this situation. Does anyone know how to solve this?

This is my method to solve the problem, but I don't know how to manage problem.

studentlist=[]
menu=1
while menu!=0:
    print ("""
1. Add new student records
2. Show all student records
3. Delete a student record
4. Dislay overall average coursework mark
5. Display overall average exam mark
6. Display all aggregate marks
7. Display overall average aggregate mark
0. Exit
Plese select an option
       """)
    menu=int(input(""))

    
    if menu==1:
        promptdict1 = {'name': 'Enter a students name: ', \
                       'cmark': 'Enter the students coursework mark: ', \
                       'emark': 'Enter the students exam mark: '}
        studentlist.append({'name': input(promptdict1['name']), \
                            'cmark': int(input(promptdict1['cmark'])), \
                            'emark': int(input(promptdict1['emark']))})
        print(studentlist[-1])


        
    elif menu==2:
        promptdict2 = {'name': 'Name:', \
                       'cmark': 'Courswork mark:', \
                       'emark': 'Exam mark:'}
        for student in studentlist:
            print(promptdict2['name'], student['name'])
            print(promptdict2['cmark'], student['cmark'])
            print(promptdict2['emark'], student['emark'], '\n')


            
    elif menu==3:
        name=input("Enter a students name: ")
        for n in studentlist:
            if n['name']==name:
                studentlist.remove(n)

    elif menu==4:
        total=0
        total_students=len(studentlist)
        for n in studentlist:
             total+=n['cmark']
        print("Overall average coursework mark: "+str(total/total_students))
         
            
    elif menu==5:
        total=0
        total_students2=len(studentlist)
        for n in studentlist:
             total+=n['emark']
        print("Overall average Exam mark: "+str(total/total_students2))
                       
        

    elif menu==0:
        break
                
tab
  • 25
  • 4
  • 1
    For retrieving the sum you can set a variable to zero before the loop and in the loop add for each student the coursework mark to the variable. For a list like the one given here, "len" returns the number of entries in the list. – Michael Butscher Dec 15 '22 at 22:06
  • If you want to use "sum" you should know first what a generator expression is. Do you? – Michael Butscher Dec 15 '22 at 22:10
  • Does this answer your question? [Get average value from list of dictionary](https://stackoverflow.com/questions/29027792/get-average-value-from-list-of-dictionary) – Pranav Hosangadi Dec 16 '22 at 16:17
  • Please also read [How do I ask and answer homework questions?](//meta.stackoverflow.com/q/334822/843953) and [Open letter to students with homework problems](//softwareengineering.meta.stackexchange.com/q/6166/39188) and [How much research effort is expected of Stack Overflow users?](//meta.stackoverflow.com/a/261593/843953) When you ask a homework question, you need to show your effort towards solving the problem that you are _currently asking about_. Solving some previous parts of the overall assignment and asking us to do the rest is cheating on your homework. – Pranav Hosangadi Dec 16 '22 at 16:22

1 Answers1

0

It is impossible to delete only a name from tuple, you should to delete everything from tuple - if the name you just entered == to name in tuple. So it will looks like:

elif menu==3:
        name=input("Enter a students name: ")
        promptdict3 = {'name': 'Enter a students name: ', \
                       'cmark': 'Enter the students coursework mark: ', \
                       'emark': 'Enter the students exam mark: '}
        for n in studentlist:
            if n['name']==name:
                studentlist.remove(n)
                
            print()

        promptdict2 = {'name': 'Name:', \
                       'cmark': 'Courswork mark:', \
                       'emark': 'Exam mark:'}
        for student in studentlist:
            print(promptdict2['name'], student['name'])
            print(promptdict2['cmark'], student['cmark'])
            print(promptdict2['emark'], student['emark'], '\n')

tab
  • 25
  • 4