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 - 358 Views - Last Post: 25 July 2012 - 08:01 AM
#1
So Many Errors...
Posted 24 July 2012 - 08:12 AM
Replies To: So Many Errors...
#2
Re: So Many Errors...
Posted 24 July 2012 - 08:19 AM
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
#4
Re: So Many Errors...
Posted 24 July 2012 - 08:29 AM
BayseVT, on 24 July 2012 - 05:27 PM, said:
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:
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
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
#7
Re: So Many Errors...
Posted 24 July 2012 - 08:37 AM
#8
Re: So Many Errors...
Posted 24 July 2012 - 08:41 AM
#9
Re: So Many Errors...
Posted 24 July 2012 - 08:51 AM
#10
Re: So Many Errors...
Posted 25 July 2012 - 07:06 AM
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
#12
Re: So Many Errors...
Posted 25 July 2012 - 07:35 AM
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
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.
|
|

New Topic/Question
Reply



MultiQuote





|