How do I find the range of integers in a text file with python
after finding the average of values in my text file, I am wondering how I would find the range of the same values in the same text file.
What I have now:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' +str(score))
file.close()
with open('stats.txt') as fh:
sum = 0
count = 0
for line in fh:
count += 1
sum += float(line.split()[1])
average = sum / count
#add range here
file = open('maths.txt', 'w+')
file.write('Average: ' + str(average))
file.close()
The text file stats.txt looks like this:
Score: 3
Score: 0
Score: 13
Score: 13
Score: 9
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 31
Score: 0
Score: 0
Score: 0
Score: 0
Score: -8
Score: 0
Score: 0
Thanks for helping
python range text-files
add a comment |
after finding the average of values in my text file, I am wondering how I would find the range of the same values in the same text file.
What I have now:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' +str(score))
file.close()
with open('stats.txt') as fh:
sum = 0
count = 0
for line in fh:
count += 1
sum += float(line.split()[1])
average = sum / count
#add range here
file = open('maths.txt', 'w+')
file.write('Average: ' + str(average))
file.close()
The text file stats.txt looks like this:
Score: 3
Score: 0
Score: 13
Score: 13
Score: 9
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 31
Score: 0
Score: 0
Score: 0
Score: 0
Score: -8
Score: 0
Score: 0
Thanks for helping
python range text-files
1
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
Append yourfloat(line.split()[1]
values to a list and then usemax
andmin
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.
– Dascienz
Nov 19 '18 at 22:51
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57
add a comment |
after finding the average of values in my text file, I am wondering how I would find the range of the same values in the same text file.
What I have now:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' +str(score))
file.close()
with open('stats.txt') as fh:
sum = 0
count = 0
for line in fh:
count += 1
sum += float(line.split()[1])
average = sum / count
#add range here
file = open('maths.txt', 'w+')
file.write('Average: ' + str(average))
file.close()
The text file stats.txt looks like this:
Score: 3
Score: 0
Score: 13
Score: 13
Score: 9
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 31
Score: 0
Score: 0
Score: 0
Score: 0
Score: -8
Score: 0
Score: 0
Thanks for helping
python range text-files
after finding the average of values in my text file, I am wondering how I would find the range of the same values in the same text file.
What I have now:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' +str(score))
file.close()
with open('stats.txt') as fh:
sum = 0
count = 0
for line in fh:
count += 1
sum += float(line.split()[1])
average = sum / count
#add range here
file = open('maths.txt', 'w+')
file.write('Average: ' + str(average))
file.close()
The text file stats.txt looks like this:
Score: 3
Score: 0
Score: 13
Score: 13
Score: 9
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 0
Score: 31
Score: 0
Score: 0
Score: 0
Score: 0
Score: -8
Score: 0
Score: 0
Thanks for helping
python range text-files
python range text-files
edited Nov 20 '18 at 9:19
Jay W
asked Nov 19 '18 at 22:46
Jay WJay W
11
11
1
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
Append yourfloat(line.split()[1]
values to a list and then usemax
andmin
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.
– Dascienz
Nov 19 '18 at 22:51
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57
add a comment |
1
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
Append yourfloat(line.split()[1]
values to a list and then usemax
andmin
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.
– Dascienz
Nov 19 '18 at 22:51
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57
1
1
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
Append your
float(line.split()[1]
values to a list and then use max
and min
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.– Dascienz
Nov 19 '18 at 22:51
Append your
float(line.split()[1]
values to a list and then use max
and min
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.– Dascienz
Nov 19 '18 at 22:51
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57
add a comment |
1 Answer
1
active
oldest
votes
Something like this:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' + str(1))
file.close()
numbers =
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average: ' + str(sum(numbers)/len(numbers)) + "n")
file.write('Max: ' + str(max(numbers)) + "n")
file.write('Min: ' + str(min(numbers)) + "n")
file.close()
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383740%2fhow-do-i-find-the-range-of-integers-in-a-text-file-with-python%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
Something like this:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' + str(1))
file.close()
numbers =
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average: ' + str(sum(numbers)/len(numbers)) + "n")
file.write('Max: ' + str(max(numbers)) + "n")
file.write('Min: ' + str(min(numbers)) + "n")
file.close()
add a comment |
Something like this:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' + str(1))
file.close()
numbers =
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average: ' + str(sum(numbers)/len(numbers)) + "n")
file.write('Max: ' + str(max(numbers)) + "n")
file.write('Min: ' + str(min(numbers)) + "n")
file.close()
add a comment |
Something like this:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' + str(1))
file.close()
numbers =
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average: ' + str(sum(numbers)/len(numbers)) + "n")
file.write('Max: ' + str(max(numbers)) + "n")
file.write('Min: ' + str(min(numbers)) + "n")
file.close()
Something like this:
file = open('stats.txt', 'a+')
file.write('n' + 'Score: ' + str(1))
file.close()
numbers =
with open('stats.txt') as fh:
count = 0
for line in fh:
count += 1
numbers.append(float(line.split()[1]))
file = open('maths.txt', 'w+')
file.write('Average: ' + str(sum(numbers)/len(numbers)) + "n")
file.write('Max: ' + str(max(numbers)) + "n")
file.write('Min: ' + str(min(numbers)) + "n")
file.close()
answered Nov 19 '18 at 23:11


BiasuBiasu
83211
83211
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53383740%2fhow-do-i-find-the-range-of-integers-in-a-text-file-with-python%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
what do you mean by range - minimum maximum? standard deviation?
– miraculixx
Nov 19 '18 at 22:49
Append your
float(line.split()[1]
values to a list and then usemax
andmin
? Alternatively, you could sort your file using a command-line tool and then grab the first and last values.– Dascienz
Nov 19 '18 at 22:51
"after finding the range of values in my text file, I am wondering how I would find the range of the same values in the same text file" I'm not sure what this means. Do the same thing again?
– slider
Nov 19 '18 at 22:57