Unable to get crct output

I did all well but still i cant get crct ouptut as shown here below this text…

EXAMPLE:

>>> Enter a student’s assessment marks (separated by comma), type in letter N to finish:
>>> 40,100,0
>>> Enter a student’s assessment marks (separated by comma), type in letter N to finish:
>>> 50,50,40
>>> What is this student’s supplementary exam mark:
>>> 67
>>> Enter a student’s assessment marks (separated by comma), type in letter N to finish:
>>> 90,100,100
>>> Enter a student’s assessment marks (separated by comma), type in letter N to finish:
>>> N
>>> Number of students: 3
>>> Student pass rate: 66.67%
>>> Student pass rate (adjusted): 66.67%
>>> Average mark for Assessment 1: 60.00
>>> Average mark for Assessment 2: 83.33
>>> Average mark for Assessment 3: 46.67
>>> Average final mark: 64.00
>>> Average grade point: 1.5
>>> Number of HDs: 1
>>> Number of Ds: 0
>>> Number of Cs: 0
>>> Number of Ps: 0
>>> Number of SPs: 1
>>> Number of Fs: 1

import math
avg1 = 0;avg2 = 0;avg3 = 0;favg = 0
l = []
while True:
    user_input = input("Enter a student's assessment marks(seperated by comma):")
    if user_input == "N":break
    a1,a2,a3 = eval(user_input)
    avg1 += a1; avg2 += a2; avg3 += a3
    f = (math.ceil(a1 * 0.2 + a2 * 0.4 + a3 * 0.4))
    favg += f
    g = ""
    if f >= 85 and f <= 100:
        g = "HD"
    elif f >= 75  and f < 85:
        g = "D"
    elif f >= 65  and f < 75:
        g = "C"
    elif f >= 50  and f < 65:
        g = "P"
    elif f >= 45 and f <= 50:
        if any([34<a1<50,34<a2<50]) and a3>49 or 34<a3<50:
            s = int(input("Enter supplementary marks : "))
            if s >= 50:
                g = "SP"
                
        else:
            g = "F"
    else :
        if all([a1 == 0 and a2 == 0 or a1 == 0 and a3 == 0 or a2 == 0 and a3 == 0]):
             if all([a1 == 0 or a2 == 0 or a3 == 0]):
                 g = "AF"  
        else:
            g = "F"
    l.append([f,g])
print("Number of students : ",len(l))
for i in l:
    HD = i.count("HD")
    D = i.count("D")
    C = i.count("C")
    P = i.count("P")
    SP = i.count("SP")
    F = i.count("F")
    AF = i.count("AF")
spr = ((HD+D+C+P+SP)/len(l))*100
spra = ((HD+D+C+P+SP)/len(l)-AF)*100
agp =((HD*4.0)+(D*3.0)+(C*2.0)+P+(SP*0.5))/len(l)

print("Student pass rate:",spr)
print("Student pass rate (adjusted): ",spra)
print("Average mark for Assessment 1: %.2f"%(avg1/len(l)))
print("Average mark for Assessment 2: %.2f"%(avg2/len(l)))
print("Average mark for Assessment 3: %.2f"%(avg3/len(l)))
print("Average final mark: %.2f"%(favg/len(l)))
print("Average grade point: %.1f"%(agp))
print("Number of HD's:",HD)
print("Number of D's:",D)
print("Number of C's:",C)
print("Number of P's:",P)
print("Number of SP's:",SP)
print("Number of F's:",F)





and my output for it …

Enter a student's assessment marks(seperated by comma):40,100,0
Enter a student's assessment marks(seperated by comma):50,50,40
Enter supplementary marks : 67
Enter a student's assessment marks(seperated by comma):90,100,100
Enter a student's assessment marks(seperated by comma):N
Number of students :  3
Student pass rate: 0.3333333333333333%
Student pass rate (adjusted):  33.33333333333333
Average mark for Assessment 1: 60.00
Average mark for Assessment 2: 83.33
Average mark for Assessment 3: 46.67
Average final mark: 64.00
Average grade point: 1.3
Number of HD's: 1
Number of D's: 0
Number of C's: 0
Number of P's: 0
Number of SP's: 0
Number of F's: 0

Well you got a couple problems in this one thing.
First you have to check if the input is a “N” at some point and if so, leave the loop - either by using a break or setting it’s running-condition to False (which implies making it a variable).

However for this you need to change the way your input works, as of now it’s considered a tuple and followed by an equation which both will run into an error, if not provided with exactly three numbers.

Easiest way to do this is by creating a condition which checks what the input is and then splits it into numbers, if needed.

please can you help with condition to be inserted

Just put it at the start.
Turn the input into a seperat variable, if it is “N” break, if not use eval on it, followed by the rest of the code.

sorry i didnt undertood can you please type in to describe

Here is an example on how it could work:

while True:
  user_input = input(...)
  if user_input == break_condition:
    break
    #break exits the loop
  [--other code--]

nope although it didnt worked…

After entering all marks then after typing N to stop loop then output should be display all assessments grade according to the input we entered marks

I can take my snippet, adjust it to fit your code and get such a result:

Enter a student's assessment marks(seperated by comma):100,100,5
P
Enter a student's assessment marks(seperated by comma):N

And the program is finished.
If it doesn’t work on your side, maybe you didn’t adjust the snippet to your actual code.
I only wrote some generic code, you cannot simply copy-paste it → because you are supposed to write you own code with help of the forum, not the forum writing code for you.

i got that output but after entering N it showing N is not defined

Sounds like you still have the input in the eval - eval is trying to turn the input-string into Python code. So if you enter “N” it thinks this is the name of a variable.

You have to seperate those.

user_input = input(...)
if user_input == "N": break
a,b,c = eval(user_input)

thanks a lot i got it but not exactly how i mean output shld be in this way i cant fix it …

"Enter a student's assessment marks(seperated by comma):"
10,1,1
"Enter a student's assessment marks(seperated by comma):"
90,100,100
"Enter a student's assessment marks(seperated by comma):"
N
#after pressing N all grades for this exact meaning of code shld here like..
F
HD

So you want the output to happen AFTER the loop is finished?
Well then you need to save the calculated grades somewhere (like a list) and print the content of the list once the loop is finished.

thanks after i implement it ill come back to greet you

Thanks a lot​:yum::gift:… It worked and fixed my problem…

I cant fix it again i worked all types …

Can you describe your problem?

i need the output as shown there starting as student pass rate = 66.67%
but i got student pass rate = 0.6666666666
we need to calculate student pass rate according to given instructions in that picture. i followed also i got invalid output

So you output has the right value, but you need to turn it from a standard float into a string representing the percentage.
That shouldn’t be to hard :wink:

round(variable, number of decimal places)
ex:

x = 2.6666666666666666666666
x = round(x,2)
print(x)
2.67

Btw, you don’t need to put so many conditions in your if/elif statements. The elifs only run if the preceding condition was false, so it’s perfectly fine to run something like this:

if score >= 90:
    print('A')
elif score >= 80:
    print('B')
elif score >= 70:
    print('C')

etc etc. A score of 95 will only trigger the print(‘A’) even though 95 is greater than both 80 and 70 because it will never even make those comparisons if it satisfies the original if statement.