12 Replies - 504 Views - Last Post: 25 July 2012 - 08:01 AM Rate Topic: -----

#1 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

So Many Errors...

Posted 24 July 2012 - 08:12 AM

My program won't even run because of some error messages that are displaying...any help is appreciated, I don't think there is anything majorly wrong with my code.

 def getScore(counter,Name):

    while true:
    try:
score=raw_input(‘Enter score for “+str(Name)+” number “ +str(counter)+”:”)


    if isinstance(score, int):

    return score

    except ValueError:

    print(“You must enter integer number…try again”)

def getQuizSum():

    numQuiz=int(raw_input(‘Enter the number of quizzes to sum: ’))

    quizList=[]
    quizSum=0

    for i in range(numQuiz):

    score=getScore(i,”quiz”)
    quizList.append(score)

    for i in range(numQuiz):
    quizSum=quizSum+quizList[i]

    print “The sum of all quizzes add up to “ ,quizSum
    return quizSum

def getHomeworkAvg():

    numHW=int(raw_input(‘Enter the number of Homework grades to average: ‘))

    homeworkList=[]
    homeworkSum=0
    homeworkAvg=0

    for i in range(numHW):
    score=getScore(i, “homework”)

    homeworkList.append(score)

    for i in range(numHW):
    homeworkSum=homeworkSum+homeworkList[i]
    homeworkAvg=homeworkSum/numHW

    print “The average of all homework grades are, “, homeworkAvg
    return homeworkAvg

def getTestSum():

    numTest=int(raw_input(‘Enter the number of tests to sum’))

    testList=[]
    testSum=0

    for i in range(numTest):
    score=getScore(i,”test”)
    testList.append(score)

    for i in range(numtest):
    testSum=testSum+testList[i]

    print “The sum of all tests add up to “ ,testSum
    return testSum

def getGradeTotal(quizSum, homeworkAvg, testSum):

    gradeTotal=quizSum+homeworkAvg+testSum
    print "The grade total is ",gradeTotal
    return gradeTotal

    def displayGrade(gradeTotal):
    if gradeTotal > 630:
    print "The grade is an A!"
    if gradeTotal < 631 and gradeTotal > 560:
    print "The grade is a B!"
    if gradeTotal < 561 and gradeTotal > 420:
    print "The grade is a C..."
    if gradeTotal < 421 and gradeTotal > 350:
    print "The grade is a D..."
    if gradeTotal < 421:
    print "The grade is an F..."

def main():
    quizSum=getQuizSum()

    homeworkAvg=getHomeworkAvg()
    testSum=getTestSum()
    gradeTotal=getGradeTotal(quizSum, homeworkAvg, testSum)

    displayGrade(gradeTotal)

main()



Is This A Good Question/Topic? 0
  • +

Replies To: So Many Errors...

#2 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,106
  • Joined: 19-March 11

Re: So Many Errors...

Posted 24 July 2012 - 08:19 AM

Please provide a little more information.

What's the error output? What's the purpose of the program? (yes, I can guess. no, I shouldn't have to guess, because that's a source of error and confusion)

State the problem clearly, it's the first step towards solving it.

Looks like you've got some indent issues, to begin with. Every time you see a colon, like for example here:


while true:


You are defining a scope. Any lines which belong to that scope must be indented. If there's no indentation, it's an error.

This post has been edited by jon.kiparsky: 24 July 2012 - 08:21 AM

Was This Post Helpful? 1
  • +
  • -

#3 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

Re: So Many Errors...

Posted 24 July 2012 - 08:27 AM

I'm getting some sort of "Indent block" error in lines two and three. For this program, I am supposed to take the user input and add four quiz scores together, getting the sum. Then I am supposed to get 4 homework grades and take the average. Next I take two test grades and get the sum, then I add the quiz sum, homework average, and the test sum all together and display it back to the user. The quiz sum and homework average functions have to be arrays.
Was This Post Helpful? 0
  • +
  • -

#4 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2114
  • View blog
  • Posts: 3,240
  • Joined: 21-June 11

Re: So Many Errors...

Posted 24 July 2012 - 08:29 AM

Another error is that True and False are written with a capital T and F respectively.

View PostBayseVT, on 24 July 2012 - 05:27 PM, said:

I'm getting some sort of "Indent block" error in lines two and three.


In the future you should copy and paste your error messages here. Vagueing them up like that doesn't really make them more useful to us.

That said Jon already explained to you why you get indentation errors.
Was This Post Helpful? 1
  • +
  • -

#5 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,106
  • Joined: 19-March 11

Re: So Many Errors...

Posted 24 July 2012 - 08:34 AM

View PostBayseVT, on 24 July 2012 - 10:27 AM, said:

I'm getting some sort of "Indent block" error in lines two and three.



Yes, see my edited post for that.

while True:
    statementInBlock # these will repeat until True is false
    statementInBlock
    if night == day:
         black = white  # secondary blocks also indented
    statementInBlock

StatementNotInBlock   #these will not repeat
StatementNotInBlock


Quote

For this program, I am supposed to take the user input and add four quiz scores together, getting the sum. Then I am supposed to get 4 homework grades and take the average. Next I take two test grades and get the sum, then I add the quiz sum, homework average, and the test sum all together and display it back to the user. The quiz sum and homework average functions have to be arrays.


Fix the indentations and the capitalization that Sepp points out, and see if you're still having trouble.
Was This Post Helpful? 0
  • +
  • -

#6 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

Re: So Many Errors...

Posted 24 July 2012 - 08:35 AM

Alright, I fixed the indentation errors. In line 5 at the last ), I am getting an error message that says "EOL while scanning string literal."
Was This Post Helpful? 0
  • +
  • -

#7 jon.kiparsky  Icon User is offline

  • Pancakes!
  • member icon


Reputation: 7747
  • View blog
  • Posts: 13,106
  • Joined: 19-March 11

Re: So Many Errors...

Posted 24 July 2012 - 08:37 AM

You use a single quote to open the String, and a double quote to end it - python doesn't see that double quote as ending the String opened with a single quote, it just sees a random double quote character.
Was This Post Helpful? 0
  • +
  • -

#8 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

Re: So Many Errors...

Posted 24 July 2012 - 08:41 AM

Okay, so I fixed the indentation and capitalization, I also corrected the string. I am running in to a syntax error in line 12 with "except" highlighted.
Was This Post Helpful? 0
  • +
  • -

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6063
  • View blog
  • Posts: 23,517
  • Joined: 23-August 08

Re: So Many Errors...

Posted 24 July 2012 - 08:51 AM

Repost your code, in code tags, as it now stands.
Was This Post Helpful? 0
  • +
  • -

#10 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

Re: So Many Errors...

Posted 25 July 2012 - 07:06 AM

I am receiving a syntax error in the getScore function using except.

 def getScore(counter,Name):
    while True:
            try:
                score=raw_input('Enter score for “+str(Name)+” number “ +str(counter)+”:')
                if isinstance(score, int):

                    return score

                except ValueError:

                print(“You must enter integer number…try again”)

def getQuizSum():

    numQuiz=int(raw_input(‘Enter the number of quizzes to sum: ’))

    quizList=[]
    quizSum=0

    for i in range(numQuiz):

    score=getScore(i,”quiz”)
    quizList.append(score)

    for i in range(numQuiz):
    quizSum=quizSum+quizList[i]

    print “The sum of all quizzes add up to “ ,quizSum
    return quizSum

def getHomeworkAvg():

    numHW=int(raw_input(‘Enter the number of Homework grades to average: ‘))

    homeworkList=[]
    homeworkSum=0
    homeworkAvg=0

    for i in range(numHW):
    score=getScore(i, “homework”)

    homeworkList.append(score)

    for i in range(numHW):
    homeworkSum=homeworkSum+homeworkList[i]
    homeworkAvg=homeworkSum/numHW

    print “The average of all homework grades are, “, homeworkAvg
    return homeworkAvg

def getTestSum():

    numTest=int(raw_input(‘Enter the number of tests to sum’))

    testList=[]
    testSum=0

    for i in range(numTest):
    score=getScore(i,”test”)
    testList.append(score)

    for i in range(numtest):
    testSum=testSum+testList[i]

    print “The sum of all tests add up to “ ,testSum
    return testSum

def getGradeTotal(quizSum, homeworkAvg, testSum):

    gradeTotal=quizSum+homeworkAvg+testSum
    print "The grade total is ",gradeTotal
    return gradeTotal

    def displayGrade(gradeTotal):
    if gradeTotal > 630:
    print "The grade is an A!"
    if gradeTotal < 631 and gradeTotal > 560:
    print "The grade is a B!"
    if gradeTotal < 561 and gradeTotal > 420:
    print "The grade is a C..."
    if gradeTotal < 421 and gradeTotal > 350:
    print "The grade is a D..."
    if gradeTotal < 421:
    print "The grade is an F..."

def main():
    quizSum=getQuizSum()

    homeworkAvg=getHomeworkAvg()
    testSum=getTestSum()
    gradeTotal=getGradeTotal(quizSum, homeworkAvg, testSum)

    displayGrade(gradeTotal)

main()


Was This Post Helpful? 0
  • +
  • -

#11 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2114
  • View blog
  • Posts: 3,240
  • Joined: 21-June 11

Re: So Many Errors...

Posted 25 July 2012 - 07:12 AM

The except ValueError: needs to be indented at the same level as the try: it belongs to.
Was This Post Helpful? 0
  • +
  • -

#12 BayseVT  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 06-July 12

Re: So Many Errors...

Posted 25 July 2012 - 07:35 AM

Ok, I have fixed the indentations. My program will now run, it's just not doing what I want it to do. I will repost the code as it is now.
 def getScore(counter,Name):
    while True:
            try:
                score=raw_input('Enter score for “+str(Name)+” number “ +str(counter)+”:')
                if isinstance(score, int):

                    return score

            except ValueError:

                    print("You must to enter integer number…try again")

def getQuizSum():

    numQuiz=int(raw_input("Enter the number of quizzes to sum: "))

    quizList=[]
    quizSum=0

    for i in range(numQuiz):

        score=getScore(i,'quiz')
        quizList.append(score)

    for i in range(numQuiz):
        quizSum=quizSum+quizList[i]

        print ('The sum of all quizzes add up to ' ,quizSum)
        return quizSum

def getHomeworkAvg():

    numHW=int(raw_input("Enter the number of Homework grades to average: "))

    homeworkList=[]
    homeworkSum=0
    homeworkAvg=0

    for i in range(numHW):
        score=getScore(i, 'homework')

        homeworkList.append(score)

    for i in range(numHW):
        homeworkSum=homeworkSum+homeworkList[i]
        homeworkAvg=homeworkSum/numHW

        print ('The average of all homework grades are, ', homeworkAvg)
        return homeworkAvg

def getTestSum():

    numTest=int(raw_input("Enter the number of tests to sum"))

    testList=[]
    testSum=0

    for i in range(numTest):
        score=getScore(i,'test')
        testList.append(score)

    for i in range(numtest):
        testSum=testSum+testList[i]

        print('The sum of all tests add up to ' ,testSum)
        return testSum

def getGradeTotal(quizSum, homeworkAvg, testSum):

    gradeTotal=quizSum+homeworkAvg+testSum
    print "The grade total is ",gradeTotal
    return gradeTotal

    def displayGrade(gradeTotal):
        if gradeTotal > 630:
            print "The grade is an A!"
        if gradeTotal < 631 and gradeTotal > 560:
            print "The grade is a B!"
        if gradeTotal < 561 and gradeTotal > 420:
            print "The grade is a C..."
        if gradeTotal < 421 and gradeTotal > 350:
            print "The grade is a D..."
        if gradeTotal < 421:
            print "The grade is an F..."

def main():
    quizSum=getQuizSum()

    homeworkAvg=getHomeworkAvg()
    testSum=getTestSum()
    gradeTotal=getGradeTotal(quizSum, homeworkAvg, testSum)

    displayGrade(gradeTotal)

main()



The program is asking me for the number of quizzes I want summed up, so I input 4. Then it asked me this: re for “+str(Name)+” number “ +str(counter)+”, however after I input the number it still asks me this over and over. I am sorry for long time of reply my English is not perfect.
Was This Post Helpful? 0
  • +
  • -

#13 sepp2k  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2114
  • View blog
  • Posts: 3,240
  • Joined: 21-June 11

Re: So Many Errors...

Posted 25 July 2012 - 08:01 AM

The raw_input function always returns a string. So your if condition, which checks whether the value returned by raw_input is an int, will never be true. That's why the loop will loop forever.

I should also be pointed out, that your try-except construct is usually pointless, since no expression in the try-block can actually throw an exception.

What you should do is you should try to convert the string to an integer and if that succeeds (i.e. doesn't throw an exception), you should return from the function. So you can get rid of the if.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1