Nov-12-2019, 07:20 PM
I am making an accommodation program and I ran into this error.I saw other threads with the same issue om the site but they didn't help me figure it out. I am running into the error after I search the realtor file for a match. That is the login part of the program, when a student logs in.
This is my main file:
Thank you
This is my main file:
from classes.users import Student, Realtor import csv # declaration of files students_file = "students.txt" realtor_file = "realtor.txt" def main(): prompt() option_select() def prompt(): print("Welcome to Mason Real Estate") print("Please Login or Create Account") # selection to crete account or login def option_select(): print("1. Create Account \n2. Login\n") user_choice = int(input("What would you like to to today?: ")) if user_choice == 1: create_user() elif user_choice == 2: login_user() # choice to create student or realtor account def create_user(): print("Are you a student or realtor?") print("1. Student \n2. Realtor\n") role = int(input("You are: ")) if role == 1: is_student() elif role == 2: is_realtor() # choice to lgin student or realtor def login_user(): print("Student or Realtor?") print("1. Student \n2. Realtor\n") login_type = int(input("You are: ")) if login_type == 1: student_login() elif login_type == 2: realtor_login() # when create account is student def is_student(): print("\nPlease complete the following: ") user = Student(input("Username: ").capitalize(), input("Phone: ").capitalize()) # call method from student class user.create_account(user.username, user.phone) # when crete acount is realtor def is_realtor(): print("\nPlease complete information about yourself and you r rental: ") user = Realtor(input("Username: "), input("Phone number: "), input("City: "), input("Suburb: "), input("Rooms: ")) # call method from realtor class user.create_account(user.username, user.phone_number, user.city, user.suburb, user.rooms) def student_login(): found = False print("\nPlease login") while not found: # imput of details to login name = input("Enter your name: ").capitalize() phone = input("Number: ").capitalize() # open student file with open(students_file, 'r') as all_students: student_data = csv.reader(all_students) for student in student_data: # check if input has matches in file if (name and phone) in student: print("\nWelcome " + name.capitalize()) search_apartment() found = True break else: print("User not found. Try again") break all_students.close() def realtor_login(): pass def search_apartment(): print("What kind of a place would you like?: ") find = Realtor(input("What city?: ").capitalize(), input("What suburb?: ").capitalize(), input("How manny room?: ").capitalize()) find.apartment_info(find.city, find.suburb, find.rooms) main()This is where my classes are:
import csv WRITE = 'w' APPEND = 'a' READWRITE = 'w+' # class for students class Student: def __init__(self, username, phone): self.username = username self.phone = phone # method to create student account def create_account(self, username, phone): self.username = username self.phone = phone # create syudent file and append it students_file = "students.txt" file = open(students_file, mode=APPEND) file.write(username + "," + phone + "\n") file.close() print("\nThank You. Your Account has been created successfully") # realtor class class Realtor: def __init__(self, username, phone_number, city, suburb, rooms): self.username = username self.phone_number = phone_number self.city = city self.suburb = suburb self.rooms = rooms # method to create realtor account def create_account(self, username, phone_number, city, suburb, rooms): self.username = username self.phone_number = phone_number self.city = city self.suburb = suburb self.rooms = rooms # create realtor file and append to it realtor_file = "realtor.txt" file = open(realtor_file, mode=APPEND) file.write(username + "," + phone_number + "," + city + "," + suburb + "," + rooms + "\n") print("\nThank You. Your Account has been created successfully") def apartment_info(self, city, suburb, rooms): self.city = city self.suburb = suburb self.rooms = rooms realtor_file = "realtor.txt" # open realtor file with open(realtor_file, 'r') as all_realtors: realtor_data = csv.read(all_realtors) # check if searched parameter exist in the file for realtor in realtor_data: if (city and suburb and rooms) in realtor: print("Found") all_realtors.close() def apart_info(self): return '{} {} {}'.format(self.city, self.suburb, self.rooms)And the error:
Traceback (most recent call last): File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 112, in <module> main() File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 11, in main option_select() File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 28, in option_select login_user() File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 48, in login_user student_login() File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 90, in student_login search_apartment() File "C:/Users/Jacques/PycharmProjects/Mason_Housing/main.py", line 107, in search_apartment input("How manny room?: ").capitalize()) TypeError: __init__() missing 2 required positional arguments: 'suburb' and 'rooms'I have been trying to locate where I left an argument but I don't see where it is. Would you please show me what I am supposed to do
Thank you