Hi. I'm trying to make a grade forecasting program for python 2.7.
My problem is that I'm having difficulty trying to correlate the first "grade element" input with the first "grade element percentage" input.

Here's what I have so far.


## Grade Forecast

## Chandiramani Grade Forecast

import random

print \
    """
    Welcome to Your Personalized Grade Forecast Tool.
    Instructions:
    1 - View My Grade List
    2 - Add a Grade Category
    3 - Edit a Grade Category
    4 - Delete a Grade Category
    5 - Add a Grade
    6 - Edit a Grade
    7 - Delete a Grade
    8 - Add an Extra Credit Grade
    8 - Exit """

grade_total = 100

grade_elements = []
grade_elements_scores = []
user_grades = []

while (grade_total != 0):
    x = raw_input("Enter a Grade Category: ")
    x = x.upper()
    grade_elements.append(x)
    y = int(raw_input("Enter its Percentage: "))
    grade_elements_scores.append(y)
    grade_total -= y
    print "You have",grade_total,"points left."
    if (grade_total < 0):
        grade_total += y
        print "Invalid input."
        print "The Course should total 100%."
        print "You will be able to add extra credit points later."

**I don't know how to associate the two lists. Please help!

Recommended Answers

All 6 Replies

I could not get the real function of this code, so my post is pure guess....

What does it mean "associate" two lists?

If you mean to multiply each element of one list with the other list's respective element and sum them, then (given list1 and list2):
sum(a*b for a,b in zip(list1,list2))

Intuitively I think you have an error. If grade_total is invalid, you add the last y value, but you do not remove the respective grade.

I could not get the real function of this code, so my post is pure guess....

What does it mean "associate" two lists?

If you mean to multiply each element of one list with the other list's respective element and sum them, then (given list1 and list2):
sum(a*b for a,b in zip(list1,list2))

Intuitively I think you have an error. If grade_total is invalid, you add the last y value, but you do not remove the respective grade.

I've figured it out. Thanks though. Please take a look at this and provide some feedback. Thanks!

import random

print \
"""\t
  ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌
  ◌ ╔╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╦╗ ◌
  ◌ ╠═ WELCOME TO YOUR PERSONALIZED GRADE FORECASTING TOOL ═╣ ◌
  ◌ ╚╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╩╝ ◌
  ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌ ◌
    """

grade_total = 100


grade_elements = []
grade_elements_pct = []
user_grades = []

print "Step 1, You will input your course grade distribution."
print \
    """Examples of GRADE CATEGORY..
    [Quizzes, Assignments, Exam 1, Participation, Project, Final, etc.]"""

print \
      """\nRIGHT AFTER Entering Each Grade,
        You will be asked to enter its percentage in the syllabus.
\nExamples of PERCENTAGE: [74,92,85,96,etc.]
**Note: This MUST add up to 100%."""


print "\nStep 2, You Will Enter Your Portion of the Grades."

print "\nStep 3, Recieve Your Very Own Forecast!"
print "\nEnjoy!"

## We are about to recieve the grade categories and percentages
while (grade_total != 0):
    x = raw_input("\nEnter a Grade Category [quiz,hw,etc.]: ")
    x = x.upper()
    grade_elements.append(x)
    print "**Note: The Percentages must add up to 100."
    print "You have",grade_total,"points left."
    y = int(raw_input("Enter "+x+" % [out of 100]: "))
    grade_elements_pct.append(y)
    grade_total -= y
    print "You have",grade_total,"points left."
    if (grade_total < 0):
        grade_elements.remove(x)
        grade_elements_pct.remove(y)
        grade_total += y
        print "Invalid input."
        print "The Course should total 100%."
        print "You will be able to add extra credit points later."
    

raw_input("\nHit Enter To View Your Summary.")
ctr = 0
grade_total = 100
print "\nOptions: "
while (grade_total != 0):
    for i, v in enumerate(grade_elements):
        i += 1
        print ctr,"-",v,"=",grade_elements_pct[ctr],"%"
        grade_total -= grade_elements_pct[ctr]
        ctr += 1

    
ctr = 0
x = len(grade_elements)
y = []
while (ctr < x):
    y.append(ctr)
    user_grades.append(ctr)
    ctr += 1


burn = []
ctr = 0
scores = []

u = "y"

while (ctr <= x and u == "y"):
    choice = int(raw_input("\nWhich of the grade options would you like to fill out (0,1,2,etc): "))
    if (choice in y):
        print "\nWhat is your score on",grade_elements[choice],"?"
        print "Example: 100, 95, 81, etc."
        user = float(raw_input("\tScore: "))
        if user <= 100:
            scores.append(user)
            user_grades.remove(choice)
            user_grades.insert(choice, user)
            burn.append(choice)
            y.remove(choice)
            ctr += 1
            print ""
            for i in y:
                print "You still have",grade_elements[i],"available."
            u = raw_input("Would you like to enter another one of your scores? Y/N? ")
            u = u.lower()
            if (u == "n"):
               raw_input("\nHit Enter To View The Results.")
            
        else:
            print "Please enter a percentage between 0-100."
    
    
    elif (choice in burn):
        print "\nSorry, that grade has already been filled."
    elif (choice not in burn and choice not in y):
        print "\nInvalid input."

ctr = 0
ctr2 = 0
ctr3 = len(burn)
grade_total = 100
scores_pct = []
while (ctr < ctr3):
    indiv_score = float(scores[ctr])
    position2 = burn[ctr]
    position = float(grade_elements_pct[position2])
    calc = float(indiv_score * position / 100)
    scores_pct.append(calc)
    user_grades.remove(indiv_score)
    user_grades.insert(position2, calc)
    ctr += 1
    
    
ctr = 0    
y2 = []
user_grades_2 = []

# remover
while (y != []):
    b = y.pop(0)
    y2.append(b)
    user_grades.remove(b)
    user_grades.insert(b, "n/a")
    
print "\nYour Grade Breakdown: "
while (grade_total != 0):
    

    for i,v in enumerate(grade_elements):
        i += 1
        print ctr,"\t",v,"=",user_grades[ctr],"out of",grade_elements_pct[ctr],"%"
        grade_total -= grade_elements_pct[ctr]
        ctr += 1

grade_remain = 100
ctr = 0
abc = float()
ab = float()
calc = float()

while (ctr < len(burn) and scores_pct != []):
    xy = burn[ctr]
    grade_remain -= grade_elements_pct[xy]
    abc = float(scores_pct.pop(0))
    ab += abc
    ctr += 1

grade_total = 100 - grade_remain
calc = ab/grade_total
calc *= 100
print "\nYour Current Grade is :",calc,"%"
print "You still have",grade_remain,"% of your grade left to complete."

raw_input("Hit Enter To Jump To Your Forecast.")

print "Now for the Grade Forecast.."
u = 1
optimism = int(0)
while (u != 0):
    optimism = raw_input(\
        """\nOn a scale of 1-5..
        How Optimistic Do You Feel About The Remaining Grades?

        Enter 1 if you plan to slack off.
        Enter 2 if you're feeling somewhat pessimistic
        Enter 3 if you're neutral.
        Enter 4 if you're feeling good about the remainder.
        Enter 5 if your grades are only going UP UP and AWAY!

        I feel: """)
    
    if optimism == "1":
        factor = random.uniform(0.862,0.873)
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",forecast,"%"
        u -= 1
    elif optimism == "2":
        factor = random.uniform(0.951,0.965)
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",forecast,"%"
        u -= 1
    elif optimism == "3":
        factor = random.uniform(0.989,1.01)
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",calc,"%"
        u -= 1
    elif optimism == "4":
        factor = random.uniform(1.022,1.036)
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",forecast,"%"
        u -= 1
    elif optimism == "5":
        factor = random.uniform(1.073,1.0827)
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",forecast,"%"
        u -= 1
    else:
        print "Please enter a value between 1-5."
    
raw_input("Enter to exit.")

It is way too long. User input, output and logic is not separated.
If you are interested I can look at it, and make some changes to it.
Are you?

To start you off, look for redundant statements, like all of the if/elif at the end of the program that basically do the same thing. They can be replaced by a simple dictionary of values.

## The following 3 lines can be deleted for this example
#u = 1
#optimism = int(0)
#while (u != 0):
factor_dict = {"1": [0.862, 0.873],
               "2": [0.951,0.965],
               "3": [0.989,1.01],
               "4": [1.022,1.036],
               "5": [1.073,1.0827]}
optimism = ""
while optimism not in factor_dict:
    optimism = raw_input(\
        """\nOn a scale of 1-5..
        How Optimistic Do You Feel About The Remaining Grades?
 
        Enter 1 if you plan to slack off.
        Enter 2 if you're feeling somewhat pessimistic
        Enter 3 if you're neutral.
        Enter 4 if you're feeling good about the remainder.
        Enter 5 if your grades are only going UP UP and AWAY!
 
        I feel: """)
 
    if optimism in factor_dict:
        factor = random.uniform(factor_dict[0], factor_dict[1])
        forecast = calc*factor/100
        forecast *= grade_remain
        forecast += ab
        raw_input("Hit Enter To View Your Forecast.")
        print "Your FORECASTED Grade is: ",forecast,"%"
    else:
        print "Please enter a value between 1-5."

You are correct woooee, but the style of lines 12-13 I would like to write:

optimism = raw_input("""
On a scale of 1-5..

Your code is not bullet proof. its far from ok.

And i was thinking why dont you break them apart into methods in a class. It will be more handy and easy to work on it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.