Python Forum

Full Version: Calculate median for school grades per subject
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I need some help with calculating median for school grades for subject or subject and diffuculty level (..200, 300).

The text is not in english, not sure if it needs to be? If so I can probaly translate.

Just managed to calculate median for all grades but I can not get it right for per subjects.

 emner = ['INFO100','INFO104',
             'INFO200','INFO204',
             'INFO300','INFO304',
             'ECON100','ECON101',
             'ECON200','ECON251',
             'ECON310','ECON320',
             'GEO100','GEO105',
             'GEO251','GEO205',
             'GEO351','GEO350',]

fag = {'informasjonsvitenskap':'INF', 'økonomi':'ECON', 'geovitenskap':'GEO'}

karakterer = {'INFO100':'C', 'INFO104':'B', 'INFO204':'C',
                 'ECON100':'B', 'ECON101':'A', 'ECON251':'B',
                 'GEO100':'A', 'GEO105':'C', 'GEO205':'B'}
    

if handling == 4:

            tall = 0
            count = 0

            input("Velg fag og/eller emnenivå (<enter> for alle)")
            subject = input(" -Fag : ")
            level = input(" -Nivå : ")
            
            for k,v in karakterer.items():

                if v =="A":
                    tall+=6
                    count +=1
                if v =="B":
                    tall+=5
                    count +=1
                if v =="C":
                    tall+=4
                    count +=1
                if v =="D":
                    tall+=3
                    count +=1
                if v =="E":
                    tall+=2
                    count +=1
                if v =="F":
                    tall+=1
                    count +=1
                    
            snitt = tall/count
            snitt = round(snitt)
            
            if snitt == 6:
                snitt = "A"
            if snitt == 5:
                snitt = "B"
            if snitt == 4:
                snitt = "C"
            if snitt == 3:
                snitt = "D"
            if snitt == 2:
                snitt = "E"
            if snitt == 1:
                snitt = "F"
        
            
            if subject == "" and level == "":
                print(snitt)

            if subject == "" and level 
Thanks so much for all help :)
In your for k,v loop, keep additional tallies and counts for each subject and level. You will need to parse the k string - getting the characters up to and including the first numeric character.