using python 3 Given the dictionary called students which ma

using python 3

Given the dictionary called students which maps names to lists of courses taken: studentDict = {\'Joe\": [Bio\', \'Music\'], \'Sally\': [\'Chem\', \'Bio\'], \'Mike\': [\'Physics\', \'Chem\'], \'Jill\': [\'Bio\']} Create a menu that allows the user to 1. Add a student\'s info 2. Print 3. Print names 4. Delete a student\'s info 5. Print list of classes 6. Names of all students in a particular class 7. Classes for particular student 8. Check for student 9. Quit Notes: 1. addstudent --- ask the user to enter a student name and the classes they took (prompt them to enter END when finished), and insert that information into the studentDict. 2. Print the dictionary (one student\'s info per line) 3. Print the names only, sorted in alphabetical order 4. print the names of the students and ask the user which one to delete from the dictionary and delete that student. MAKE SURE TO CHECK BEFORE TRYING TO DELETE! 5. create a SORTED list of the classes taken by the students with NO DUPLICATES and print it. Ex: it should print {Bio, Chem, Music, Physics} 6. display the sorted list of classes. Allow the user to pick one of those classes, and then print the names of all of the students who took that class 7. display the names of the students, ask the user to pick one of those names, and print the classes taken by that student. 8. ask the user for a name and if they enter a name not in the dictionary, print \"That student is not in our dictionary\".

Solution

PYTHON PROGRAM

import sys
import pprint
studentDict={\'Joe\':[\'Bio\',\'Music\'],
             \'Sally\':[\'Chem\',\'Bio\'],
             \'Mike\':[\'Physics\',\'Chem\'],
             \'Jill\':[\'Bio\']}
new_list=[]
while True:
  
    print(\"1. Add a student\'s info\")
    print(\'2. Print\')
    print(\'3. Print names\')
    print(\"4. Delete a student\'s info\")
    print(\'5. Print list of classes\')
    print(\'6. Names of all students in a particular class\')
    print(\'7. Classes for particular student\')
    print(\'8. Check for student\')
    print(\'9. Quit\')

    n=int(input(\'Enter the choice \'))

    if n==1:
      
            name=input(\'Enter the name of the student to add.. \')
            if name not in studentDict:
              
                l=[]
                while True:
                    classes=input(\'Enter the class of the student...Enter END to finish \')
                    if classes==\'END\':
                        break
                    else:
                        l.append(classes)
                studentDict[name]=l
            else:
                print(\'Name already in the list\')
            print()

    elif n==2:
        pprint.pprint(studentDict)
             
          
    elif n==3:
        print()
        print(\'Student Names in the sorted order\')
        print()
        for k in sorted(studentDict.keys()):
            print(k)
        print()

    elif n==4:
        print()
        print(\'Student Names\')
        print()
        for k in sorted(studentDict.keys()):
            print(k)
        print()
        del_name=input(\"Enter the student name to delete... \")
        k=studentDict.keys()
        if del_name in k:
          
            del studentDict[del_name]
        else:
            print(\'Student is not in the dictionary\')
        print()

    elif n==5:
        print()
        l=[]
        for i in studentDict.values():
            l.append(i)
      
        for i in l:
            for j in i:
                if j not in new_list:
                    new_list.append(j)
        print(\'{\',end=\'\')
        for i in range(len(new_list)):

            if i==len(new_list)-1:
                print(new_list[i],end=\'\')
            else:
                print(new_list[i],end=\',\')
        print(\'}\')
        print()

    elif n==6:
        print()
        print(\'Sorted list of classes are \')
        print()
      
        l=[]
        for i in studentDict.values():
            l.append(i)
      
        for i in l:
            for j in i:
                if j not in new_list:
                    new_list.append(j)
      
        for c in sorted(new_list):
            print(c)
        print()

        class_name=input(\'Enter the name of the class.. \')

        print(\'Following are the students in the %s class\ \' % class_name)
        for k,v in studentDict.items():
            if class_name in v:
                print(k)

        print()

    elif n==7:

        print(\"Following are the student names\ \")
        for k in sorted(studentDict.keys()):
            print(k)

        student_name=input(\"Enter the student name.. \")

        print(\'Following are the Classes taken by the student\ \')

        classes_taken=studentDict[student_name]

        for c in classes_taken:
            print(c)
        print()

    elif n==8:
  
        name_ask=input(\"Enter the student name to check... \")
        if name_ask not in studentDict:
            print(\'That Student not in our dictionary\')
        else:
            print(\'Name found in the dictionary\')
            print()

    elif n==9:
        sys.exit(0)
      

    else:
        print()
        print(\'Enter an valid choice\')
        print()
        


SAMPLE OUTPUT

1. Add a student\'s info
2. Print
3. Print names
4. Delete a student\'s info
5. Print list of classes
6. Names of all students in a particular class
7. Classes for particular student
8. Check for student
9. Quit
Enter the choice 1
Enter the name of the student to add.. John
Enter the class of the student...Enter END to finish Bio
Enter the class of the student...Enter END to finish END

1. Add a student\'s info
2. Print
3. Print names
4. Delete a student\'s info
5. Print list of classes
6. Names of all students in a particular class
7. Classes for particular student
8. Check for student
9. Quit
Enter the choice 2

{\'Jill\': [\'Bio\'],
\'Joe\': [\'Bio\', \'Music\'],
\'John\': [\'Bio\'],
\'Mike\': [\'Physics\', \'Chem\'],
\'Sally\': [\'Chem\', \'Bio\']}
1. Add a student\'s info
2. Print
3. Print names
4. Delete a student\'s info
5. Print list of classes
6. Names of all students in a particular class
7. Classes for particular student
8. Check for student
9. Quit
Enter the choice 3

Student Names in the sorted order

Jill
Joe
John
Mike
Sally

using python 3 Given the dictionary called students which maps names to lists of courses taken: studentDict = {\'Joe\
using python 3 Given the dictionary called students which maps names to lists of courses taken: studentDict = {\'Joe\
using python 3 Given the dictionary called students which maps names to lists of courses taken: studentDict = {\'Joe\
using python 3 Given the dictionary called students which maps names to lists of courses taken: studentDict = {\'Joe\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site