Made a program that gives you the average of your school mark
Tags: programming, python, beginners, tutorial
Published: 2021-12-13 11:06:14

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")