I was doing an online course and when one of the lessons kind of lost me. Maybe I just don't remember it, but what does the "= 0" mean in the following program? I can't find any clue for it in my notes and the instructor doesn't explain it here.
**count = 0**
**total = 0**
inFile = open('grades.txt', 'r')
grade = inFile.readline()
while (grade):
print(grade)
count = count+1
total = total + int(grade)
grade = inFile.readline()
average = total / count
print("Average: " + str(average))
I feel like I'm forgetting something fundamental here.
The = operator is called the "assignment" operator. Now, plenty of people on stackoverflow are going to tell you to do your assignment yourself, but I honestly feel for you since this is such a basic question.
It's being set to 0 since later, operations like count = count + 1
require count
to have a value to begin with. Adding + 1 to None
doesn't work nicely, and even if it did, it's just nice when reading code to see variables declared in advance.
It is settings the variable value to zero
x = 0
Means set the value of x to zero.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.