I need to save Python's entered score as a text file and write a code to get the total and average by reading the score from the text file, but I've never written a code related to the text file, so can you write a code and show me? And the scores that you bring to a text file are treated as characters, so you need to convert them into numbers.
python
test.txt:
32
43
54
test.py:
sum = 0
file = open('test.txt', 'r')
point = file.readlines()
for i in point:
equal to sum += i #sum=sum+i
print(sum/len(point))
To change the result to a natural number, import the math module and
math.floor(num) #Down
Math.ceil(num) #Raised
Round(num) #Round
Use these functions. (round function built-in)
© 2024 OneMinuteCode. All rights reserved.