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()
So Many Errors...
Page 1 of 112 Replies - 353 Views - Last Post: 25 July 2012 - 08:01 AM
#1
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.
Replies To: So Many Errors...
#2
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:
You are defining a scope. Any lines which belong to that scope must be indented. If there's no indentation, it's an error.
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
#3
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.
#4
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.
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.
BayseVT, 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.
#5
Re: So Many Errors...
Posted 24 July 2012 - 08:34 AM
BayseVT, 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.
#6
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."
#7
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.
#8
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.
#9
Re: So Many Errors...
Posted 24 July 2012 - 08:51 AM
Repost your code, in code tags, as it now stands.
#10
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()
#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.
#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.
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.
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.
#13
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.
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.
Page 1 of 1
|
|

New Topic/Question
Reply



MultiQuote





|