So I'm learning about classes and objects in Python 3, but there's an error in my code ('int' object is not iterable)
class student:
name = 0
gpa = 0
def countGpa(self):
a = max(self.gpa)
print(a)
def main():
objek = student()
n = int(input("n: "))
for i in n:
objek.name = int(input("name: "))
objek.gpa = int(input("gpa: "))
objek.countGpa()
main()
I have no idea how to create an array OOP
CodePudding user response:
Only regarding your error: Convert for i in n:
to for i in range(n):
CodePudding user response:
'for i in n:' doesn't work like you want. The variable 'n' is an integer and You want an array. You want 'for i in range(n):' which creates an array of the numbers one through n.