How can I exclude my count from my grade average?












0















I'm trying to figure out how to have a count when when I want to display my file, but not have the count get added into my grade average.



def main():
choice = "q"
while choice != "X":
print_menu()
choice = input("Enter an option (D, C, X): ")
if choice == "D":
DisplayScores()
elif choice == "C":
CalcAverage()

def print_menu():
print("D. Display Grades")
print("C. Calculate Average")
print("X. Exit Application")

def DisplayScores():
try:
infile = open("data.txt",'r')
count = 0
for line in infile:
count += 1
print(count,line.rstrip("n"))
line = infile.readline()
infile.close()
except IOError:
print("File does not exist.")
except:
print("Unknown error.")

def CalcAverage():
Average = 0.0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
total = float(grade)
Average += total
print("The average of the class is: ", format(Average/29, '.2f'))
except IOError:
print("Something is wrong with the file.")
print("Unknown Error.")
datafile.close()

main()









share|improve this question

























  • What format is the data from the text file in?

    – Cory L
    Nov 21 '18 at 2:04











  • Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

    – Jab
    Nov 21 '18 at 2:09






  • 2





    I'm trying to figure out how to have a count when when I want to display my file A count of what?

    – John Gordon
    Nov 21 '18 at 2:10











  • the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

    – Brady Alger
    Nov 21 '18 at 2:22


















0















I'm trying to figure out how to have a count when when I want to display my file, but not have the count get added into my grade average.



def main():
choice = "q"
while choice != "X":
print_menu()
choice = input("Enter an option (D, C, X): ")
if choice == "D":
DisplayScores()
elif choice == "C":
CalcAverage()

def print_menu():
print("D. Display Grades")
print("C. Calculate Average")
print("X. Exit Application")

def DisplayScores():
try:
infile = open("data.txt",'r')
count = 0
for line in infile:
count += 1
print(count,line.rstrip("n"))
line = infile.readline()
infile.close()
except IOError:
print("File does not exist.")
except:
print("Unknown error.")

def CalcAverage():
Average = 0.0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
total = float(grade)
Average += total
print("The average of the class is: ", format(Average/29, '.2f'))
except IOError:
print("Something is wrong with the file.")
print("Unknown Error.")
datafile.close()

main()









share|improve this question

























  • What format is the data from the text file in?

    – Cory L
    Nov 21 '18 at 2:04











  • Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

    – Jab
    Nov 21 '18 at 2:09






  • 2





    I'm trying to figure out how to have a count when when I want to display my file A count of what?

    – John Gordon
    Nov 21 '18 at 2:10











  • the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

    – Brady Alger
    Nov 21 '18 at 2:22
















0












0








0








I'm trying to figure out how to have a count when when I want to display my file, but not have the count get added into my grade average.



def main():
choice = "q"
while choice != "X":
print_menu()
choice = input("Enter an option (D, C, X): ")
if choice == "D":
DisplayScores()
elif choice == "C":
CalcAverage()

def print_menu():
print("D. Display Grades")
print("C. Calculate Average")
print("X. Exit Application")

def DisplayScores():
try:
infile = open("data.txt",'r')
count = 0
for line in infile:
count += 1
print(count,line.rstrip("n"))
line = infile.readline()
infile.close()
except IOError:
print("File does not exist.")
except:
print("Unknown error.")

def CalcAverage():
Average = 0.0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
total = float(grade)
Average += total
print("The average of the class is: ", format(Average/29, '.2f'))
except IOError:
print("Something is wrong with the file.")
print("Unknown Error.")
datafile.close()

main()









share|improve this question
















I'm trying to figure out how to have a count when when I want to display my file, but not have the count get added into my grade average.



def main():
choice = "q"
while choice != "X":
print_menu()
choice = input("Enter an option (D, C, X): ")
if choice == "D":
DisplayScores()
elif choice == "C":
CalcAverage()

def print_menu():
print("D. Display Grades")
print("C. Calculate Average")
print("X. Exit Application")

def DisplayScores():
try:
infile = open("data.txt",'r')
count = 0
for line in infile:
count += 1
print(count,line.rstrip("n"))
line = infile.readline()
infile.close()
except IOError:
print("File does not exist.")
except:
print("Unknown error.")

def CalcAverage():
Average = 0.0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
total = float(grade)
Average += total
print("The average of the class is: ", format(Average/29, '.2f'))
except IOError:
print("Something is wrong with the file.")
print("Unknown Error.")
datafile.close()

main()






python count






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 21 '18 at 2:01









Obsidian Age

28k72344




28k72344










asked Nov 21 '18 at 1:58









Brady AlgerBrady Alger

31




31













  • What format is the data from the text file in?

    – Cory L
    Nov 21 '18 at 2:04











  • Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

    – Jab
    Nov 21 '18 at 2:09






  • 2





    I'm trying to figure out how to have a count when when I want to display my file A count of what?

    – John Gordon
    Nov 21 '18 at 2:10











  • the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

    – Brady Alger
    Nov 21 '18 at 2:22





















  • What format is the data from the text file in?

    – Cory L
    Nov 21 '18 at 2:04











  • Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

    – Jab
    Nov 21 '18 at 2:09






  • 2





    I'm trying to figure out how to have a count when when I want to display my file A count of what?

    – John Gordon
    Nov 21 '18 at 2:10











  • the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

    – Brady Alger
    Nov 21 '18 at 2:22



















What format is the data from the text file in?

– Cory L
Nov 21 '18 at 2:04





What format is the data from the text file in?

– Cory L
Nov 21 '18 at 2:04













Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

– Jab
Nov 21 '18 at 2:09





Welcome to SO, I'm seeing the question as very valid in nature, but please show us what data.txt contains or at least a sample of.. This way it's easier to formulate a response

– Jab
Nov 21 '18 at 2:09




2




2





I'm trying to figure out how to have a count when when I want to display my file A count of what?

– John Gordon
Nov 21 '18 at 2:10





I'm trying to figure out how to have a count when when I want to display my file A count of what?

– John Gordon
Nov 21 '18 at 2:10













the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

– Brady Alger
Nov 21 '18 at 2:22







the file contains grades ranging from 62 to 100 EX: 65 78 76 99 87 etc. in my program i need it to have a number before each grade as if it was a student

– Brady Alger
Nov 21 '18 at 2:22














1 Answer
1






active

oldest

votes


















0














Why are you printing the average each time through the loop? You can't know what the average is until the loop is finished. Also, it would be better to divide by the actual number of grades in the file, instead of assuming 29. Try this instead:



total = 0.0
grades = 0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
grades += 1
total += float(grade)
print("The average of the class is: ", format(total/grades, '.2f'))





share|improve this answer
























  • Holy Crap its so clear now thank you so much!!!!

    – Brady Alger
    Nov 21 '18 at 2:48











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404300%2fhow-can-i-exclude-my-count-from-my-grade-average%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Why are you printing the average each time through the loop? You can't know what the average is until the loop is finished. Also, it would be better to divide by the actual number of grades in the file, instead of assuming 29. Try this instead:



total = 0.0
grades = 0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
grades += 1
total += float(grade)
print("The average of the class is: ", format(total/grades, '.2f'))





share|improve this answer
























  • Holy Crap its so clear now thank you so much!!!!

    – Brady Alger
    Nov 21 '18 at 2:48
















0














Why are you printing the average each time through the loop? You can't know what the average is until the loop is finished. Also, it would be better to divide by the actual number of grades in the file, instead of assuming 29. Try this instead:



total = 0.0
grades = 0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
grades += 1
total += float(grade)
print("The average of the class is: ", format(total/grades, '.2f'))





share|improve this answer
























  • Holy Crap its so clear now thank you so much!!!!

    – Brady Alger
    Nov 21 '18 at 2:48














0












0








0







Why are you printing the average each time through the loop? You can't know what the average is until the loop is finished. Also, it would be better to divide by the actual number of grades in the file, instead of assuming 29. Try this instead:



total = 0.0
grades = 0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
grades += 1
total += float(grade)
print("The average of the class is: ", format(total/grades, '.2f'))





share|improve this answer













Why are you printing the average each time through the loop? You can't know what the average is until the loop is finished. Also, it would be better to divide by the actual number of grades in the file, instead of assuming 29. Try this instead:



total = 0.0
grades = 0
try:
datafile = open("data.txt", 'r')
for grade in datafile:
grades += 1
total += float(grade)
print("The average of the class is: ", format(total/grades, '.2f'))






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 21 '18 at 2:29









John GordonJohn Gordon

10.1k51730




10.1k51730













  • Holy Crap its so clear now thank you so much!!!!

    – Brady Alger
    Nov 21 '18 at 2:48



















  • Holy Crap its so clear now thank you so much!!!!

    – Brady Alger
    Nov 21 '18 at 2:48

















Holy Crap its so clear now thank you so much!!!!

– Brady Alger
Nov 21 '18 at 2:48





Holy Crap its so clear now thank you so much!!!!

– Brady Alger
Nov 21 '18 at 2:48




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53404300%2fhow-can-i-exclude-my-count-from-my-grade-average%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How to change which sound is reproduced for terminal bell?

Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

Can I use Tabulator js library in my java Spring + Thymeleaf project?