When I run this code i get an error that says. Traceback (most recent call last): File "C:\Users\ept20\OneDrive\Desktop\student_file1.py", line 49, in stu_info.add_students(name, number, email) AttributeError: 'Studentinfo' object has no attribute 'add_students'       import pathlib class Studentinfo: def __init__(self): self.student_list = [] def save_students(self): """Saving the information to the record file""" record_file = pathlib.Path("c://users//ept20//onedrive//Desktop//student_file.txt") with record_file.open(mode='a', encoding='utf-8') as file: for info in self.student_list: name, number, email = info file.write(f'{name},{number},{email}\n') def add_students(self,name,number,email): """Add a student to the student list""" student_info = (name, number, email) self.student_list.append(student_info) class Student: def __init__(self, name, number, email): self.name = name self.number = number self.email = email print(f'A new student object: {self.name} is created') def read_file(): """This method loads saved student info from the record file""" record_file = pathlib.Path("c://users//ept20//OneDrive//Desktop//student_file.txt") if record_file.exists(): print('Saved students record:') with record_file.open(mode='r') as file: for stu_list in file.readlines(): print(stu_list ,end='') else: print('No saved student record') # Load existing student records stu_info = Studentinfo() while True: name = input("Please enter students name Press 0 to quit: ") if name == '0': break number = input("Please enter the students number: ") email = input("Please enter the students email: ") stu_info.add_students(name, number, email) #After add student information, save the student list to disk stu_info.save_students() read_file()

EBK JAVA PROGRAMMING
9th Edition
ISBN:9781337671385
Author:FARRELL
Publisher:FARRELL
Chapter9: Advanced Array Concepts
Section: Chapter Questions
Problem 1CP
icon
Related questions
Question

When I run this code i get an error that says.

Traceback (most recent call last):
File "C:\Users\ept20\OneDrive\Desktop\student_file1.py", line 49, in <module>
stu_info.add_students(name, number, email)
AttributeError: 'Studentinfo' object has no attribute 'add_students'

 

 

 

import pathlib

class Studentinfo:
def __init__(self):
self.student_list = []

def save_students(self):
"""Saving the information to the record file"""
record_file = pathlib.Path("c://users//ept20//onedrive//Desktop//student_file.txt")
with record_file.open(mode='a', encoding='utf-8') as file:
for info in self.student_list:
name, number, email = info
file.write(f'{name},{number},{email}\n')

def add_students(self,name,number,email):
"""Add a student to the student list"""
student_info = (name, number, email)
self.student_list.append(student_info)

class Student:
def __init__(self, name, number, email):
self.name = name
self.number = number
self.email = email
print(f'A new student object: {self.name} is created')

def read_file():
"""This method loads saved student info from the record file"""
record_file = pathlib.Path("c://users//ept20//OneDrive//Desktop//student_file.txt")
if record_file.exists():
print('Saved students record:')
with record_file.open(mode='r') as file:
for stu_list in file.readlines():
print(stu_list ,end='')

else:
print('No saved student record')

# Load existing student records

stu_info = Studentinfo()

while True:
name = input("Please enter students name Press 0 to quit: ")
if name == '0':
break
number = input("Please enter the students number: ")
email = input("Please enter the students email: ")
stu_info.add_students(name, number, email)

#After add student information, save the student list to disk

stu_info.save_students()


read_file() 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 2 images

Blurred answer
Knowledge Booster
Files and Directory
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
EBK JAVA PROGRAMMING
EBK JAVA PROGRAMMING
Computer Science
ISBN:
9781337671385
Author:
FARRELL
Publisher:
CENGAGE LEARNING - CONSIGNMENT
Microsoft Visual C#
Microsoft Visual C#
Computer Science
ISBN:
9781337102100
Author:
Joyce, Farrell.
Publisher:
Cengage Learning,
C++ Programming: From Problem Analysis to Program…
C++ Programming: From Problem Analysis to Program…
Computer Science
ISBN:
9781337102087
Author:
D. S. Malik
Publisher:
Cengage Learning