DEV Community

Mohammad Alsuwaidi
Mohammad Alsuwaidi

Posted on

Made a program that gives you the average of your school mark

i made this program and i want help to make it better i know i can but i don't know how i feel like the code is way too long



import time
import os

task = float(input("Enter how many classes you take: "))
if task == 1:
    a = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    print "Your average is: ", a, "%"
    os.system("say %s" % a), os.system("say %s" % "Percent")
elif task == 2:
    a = float(input("Enter your grade: "))
    print "last grade"
    b = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    c = (a + b) / task
    print "Your average is: ", c, "%"
    os.system("say %s" % c), os.system("say %s" % "Percent")
elif task == 3:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    print "last grade"
    c = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    d = (a + b + c) / task
    print "Your average is: ", d, "%"
    os.system("say %s" % d), os.system("say %s" % "Percent")
elif task == 4:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    print "last grade"
    d = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    e = (a + b + c + d) / task
    print "Your average is: ", e, "%"
    os.system("say %s" % e), os.system("say %s" % "Percent")
elif task == 5:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    print "last grade"
    e = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    f = (a + b + c + d + e) / task
    print "Your average is: ", f, "%"
    os.system("say %s" % f), os.system("say %s" % "Percent")
elif task == 6:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    print "last grade"
    f = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    h = (a + b + c + d + e + f) / task
    print "Your average is: ", h, "%"
    os.system("say %s" % h), os.system("say %s" % "Percent")
elif task == 7:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    print "last grade"
    h = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    i = (a + b + c + d + e + f + h) / task
    print "Your average is: ", i, "%"
    os.system("say %s" % i), os.system("say %s" % "Percent")
elif task == 8:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    print "last grade"
    i = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    j = (a + b + c + d + e + f + h + i) / task
    print "Your average is: ", j, "%"
    os.system("say %s" % j), os.system("say %s" % "Percent")
elif task == 9:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    print "last grade"
    j = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    k = (a + b + c + d + e + f + h + i + j) / task
    print "Your average is: ", k, "%"
    os.system("say %s" % k), os.system("say %s" % "Percent")
elif task == 10:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    print "last grade"
    k = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    l = (a + b + c + d + e + f + h + i + j + k) / task
    print "Your average is: ", l, "%"
    os.system("say %s" % l), os.system("say %s" % "Percent")
elif task == 11:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    k = float(input("Enter your grade: "))
    print "last grade"
    l = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    m = (a + b + c + d + e + f + h + i + j + k + l) / task
    print "Your average is: ", m, "%"
    os.system("say %s" % m), os.system("say %s" % "Percent")
elif task == 12:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    k = float(input("Enter your grade: "))
    l = float(input("Enter your grade: "))
    print "last grade"
    m = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    n = (a + b + c + d + e + f + h + i + j + k + l + m) / task
    print "Your average is: ", n, "%"
    os.system("say %s" % n), os.system("say %s" % "Percent")
elif task == 13:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    k = float(input("Enter your grade: "))
    l = float(input("Enter your grade: "))
    m = float(input("Enter your grade: "))
    print "last grade"
    n = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    o = (a + b + c + d + e + f + h + i + j + k + l + m + n) / task
    print "Your average is: ", o, "%"
    os.system("say %s" % o), os.system("say %s" % "Percent")
elif task == 14:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    k = float(input("Enter your grade: "))
    l = float(input("Enter your grade: "))
    m = float(input("Enter your grade: "))
    n = float(input("Enter your grade: "))
    print "last grade"
    o = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    p = (a + b + c + d + e + f + h + i + j + k + l + m + n + o) / task
    print "Your average is: ", p, "%"
    os.system("say %s" % p), os.system("say %s" % "Percent")
elif task == 15:
    a = float(input("Enter your grade: "))
    b = float(input("Enter your grade: "))
    c = float(input("Enter your grade: "))
    d = float(input("Enter your grade: "))
    e = float(input("Enter your grade: "))
    f = float(input("Enter your grade: "))
    h = float(input("Enter your grade: "))
    i = float(input("Enter your grade: "))
    j = float(input("Enter your grade: "))
    k = float(input("Enter your grade: "))
    l = float(input("Enter your grade: "))
    m = float(input("Enter your grade: "))
    n = float(input("Enter your grade: "))
    o = float(input("Enter your grade: "))
    print "last grade"
    p = float(input("Enter your grade: "))
    print "calculating...."
    time.sleep(1)
    q = (a + b + c + d + e + f + h + i + j + k + l + m + n + o + p) / task
    print "Your average is: ", q, "%"
    os.system("say %s" % q), os.system("say %s" % "Percent")

Enter fullscreen mode Exit fullscreen mode

Top comments (3)

Collapse
 
reylinn profile image
ReyLinn • Edited

Hey, you could write a function that take the number of marks as parameter, asks the user to input the marks and then returns the average.
I can help you if you are stuck.

Collapse
 
tupac profile image
Mohammad Alsuwaidi

import time
import os

task = float(input("Enter how many classes you take: "))

def marks(x, y):
return x / y

if task == 1:
an = float(input("Enter your grade: "))
if an > 100:
print 'invalid'
os.system("say %s" % "invalid")
else:
print "calculating...."
time.sleep(1)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 2:
a = float(input("Enter your grade: "))
print "last grade"
b = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = a + b
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 3:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
print "last grade"
c = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(marks(), 1))), os.system("say %s" % "Percent")
elif task == 4:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
print "last grade"
d = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 5:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
print "last grade"
e = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 6:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
print "last grade"
f = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 7:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
print "last grade"
h = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 8:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
print "last grade"
i = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 9:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
print "last grade"
j = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 10:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
print "last grade"
k = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 11:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
print "last grade"
l = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k + l)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 12:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
l = float(input("Enter your grade: "))
print "last grade"
m = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k + l + m)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 13:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
l = float(input("Enter your grade: "))
m = float(input("Enter your grade: "))
print "last grade"
n = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k + l + m + n)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 14:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
l = float(input("Enter your grade: "))
m = float(input("Enter your grade: "))
n = float(input("Enter your grade: "))
print "last grade"
o = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k + l + m + n + o)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")
elif task == 15:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
l = float(input("Enter your grade: "))
m = float(input("Enter your grade: "))
n = float(input("Enter your grade: "))
o = float(input("Enter your grade: "))
print "last grade"
p = float(input("Enter your grade: "))
print "calculating...."
time.sleep(1)
an = (a + b + c + d + e + f + h + i + j + k + l + m + n + o + p)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")

elif task == 16:
a = float(input("Enter your grade: "))
b = float(input("Enter your grade: "))
c = float(input("Enter your grade: "))
d = float(input("Enter your grade: "))
e = float(input("Enter your grade: "))
f = float(input("Enter your grade: "))
h = float(input("Enter your grade: "))
i = float(input("Enter your grade: "))
j = float(input("Enter your grade: "))
k = float(input("Enter your grade: "))
l = float(input("Enter your grade: "))
m = float(input("Enter your grade: "))
n = float(input("Enter your grade: "))
o = float(input("Enter your grade: "))
p = float(input("Enter your grade: "))
print "last grade"
q = float(input("Enter your grade: "))
an = (a + b + c + d + e + f + h + i + j + k + l + m + n + o + p + q)
print "Your average is: ", (round(marks(an, task), 1)), "%"
os.system("say %s" % (round(an, 1))), os.system("say %s" % "Percent")

Collapse
 
tupac profile image
Mohammad Alsuwaidi

yeah i am kinda stuck can you please help