Python Forum
elevator simulator...whats the wrong at this code?
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
elevator simulator...whats the wrong at this code?
#1
import random

class Lift(object):
    def _init_(self,floors,passengers_in,direction  ="up",cur_floor=1):
        self.total_floors = floors
        self.reg_list = []
        self.floor = cur_floor
        self.direct = direction
    def move(self):
        if self.total_floors == self.floors:
            self.direct = "down"
        if self.direct == "up" :
            self.floor += 1
        else :
            self.floor -= 1
    def get_in(self,passenger):
        self.reg_list.append(passenger)
    def get_out(self,passenger):
        self.reg_list.remove(passenger)
        
class Building(object):
    def _init_(self,floors,passengers,lift):
        self.total_floors=floors
        self.passengers=passengers
    def run(self):
        while lift.floor != 0:
            for passenger in self.passengers:
                print(passenger)
                if lift.floor == passenger.on_floor:
                    lift.reg_list.append(passenger)
                    passenger.indicator = 1
                elif lift.floor == passenger.going_floor:
                    lift.reg_list.remove(passenger)
                    passenger.indicator = 0
                    passenger.fin = 1
            lift.move()

    def output(self):
        pass

class Passenger(object):
    def _init_(self,ID,floors,cur_floor=0,end_floor=0,in_lift=0, finished=0):
        self.ident = ID
        self.indicator = in_lift
        self.fin = finished
        cur_floor = random.randint(1, floors)
        self.on_floor = cur_floor
        end_floor = random.randint (1, floors)
        while end_floor == cur_floor:
            end_floor = random.randint(1, floors)
        self.going_floor = end_floor


passenger_count = int(input("How many passengers are in the building?: "))
floor_count = int(input("How many floors does the building have?: "))
pass_list=[]
for i in range(1,passenger_count+1):
    pass_list.append(Passenger(i,floor_count))
elevator = Elevator(floor_count,cus_list)
building = Building(floor_count,cus_list, elevator)
Reply
#2
What is wrong with this code ?
Explain what you expect to happen and what is actually happening and any errors received in error tags.
Reply
#3
Note that building.run isn't going to do anything unless you call it. I think you will get an error when you try though, as lift is not defined in run, nor is it saved in Building.__init__.
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply
#4
import random

#Σχεδιασμός 3 κλάσεων,των Lift,Building και Passenger

class Lift(object):
    def __init__(self,floors,passengers_in,direction  ="up",cur_floor=1):
        self.total_floors = floors
#Ο ανελκυστήρας αρχικά είναι άδειος        
        self.reg_list = []
        self.floor = cur_floor
        self.direct = direction

        
    def move(self):
        if self.total_floors == self.floors:
            self.direct = "down"
        if self.direct == "up" :
            self.floor += 1
        else :
            self.floor -= 1
    def get_in(self,passenger):
        self.reg_list.append(passenger)
    def get_out(self,passenger):
        self.reg_list.remove(passenger)
        
class Building(object):
    def __init__(self,floors,passengers,lift):
        self.total_floors=floors
        self.passengers=passengers
    def run(self):
        while lift.floor != 0:
            for passenger in self.passengers:
                print(passenger)
                if lift.floor == passenger.on_floor:
                    lift.reg_list.append(passenger)
                    passenger.indicator = 1
                elif lift.floor == passenger.going_floor:
                    lift.reg_list.remove(passenger)
                    passenger.indicator = 0
                    passenger.fin = 1
            lift.move()

    def output(self):
        pass

class Passenger(object):
    def __init__(self,ID,floors,cur_floor=0,end_floor=0,in_lift=0, finished=0):
        self.ident = ID
        self.indicator = in_lift
        self.fin = finished
        cur_floor = random.randint(1, floors)
        self.on_floor = cur_floor
        end_floor = random.randint (1, floors)
        while end_floor == cur_floor:
            end_floor = random.randint(1, floors)
        self.going_floor = end_floor


passenger_count = int(input("How many passengers are in the building?: "))
floor_count = int(input("How many floors does the building have?: "))
pass_list=[]
for i in range(1,passenger_count+1):
    pass_list.append(Passenger(i,floor_count))
lift = Lift(floor_count,pass_list)
building = Building(floor_count,pass_list, lift)
Reply
#5
This sounds like homework where you dont put any effort in
Recommended Tutorials:
Reply
#6
While that sounds possible, it could also be that the OP simply isn't very familiar with English.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  I have a code which is very simple but still I cannot detect what's wrong with it max22 1 440 Nov-07-2023, 04:32 PM
Last Post: snippsat
  Something wrong with my code FabianPruitt 5 787 Jul-03-2023, 10:55 PM
Last Post: Pedroski55
  Compiles Python code with no error but giving out no output - what's wrong with it? pythonflea 6 1,492 Mar-27-2023, 07:38 AM
Last Post: buran
  Video recording with Raspberry Pi - What´s wrong with my python code? Montezuma1502 3 1,192 Feb-24-2023, 06:14 PM
Last Post: deanhystad
  Why doesn't this code work? What is wrong with path? Melcu54 7 1,681 Jan-29-2023, 06:24 PM
Last Post: Melcu54
  Am I wrong or is Udemy wrong? String Slicing! Mavoz 3 2,388 Nov-05-2022, 11:33 AM
Last Post: Mavoz
  Wrong code in Python exercise MaartenRo 2 1,487 Jan-01-2022, 04:12 PM
Last Post: MaartenRo
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,603 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  VS Code debugger using wrong Python environment topfox 0 2,429 Jun-09-2021, 10:01 AM
Last Post: topfox
  Whats wrong with the elif? inunanimous93 3 2,410 Nov-30-2020, 03:58 AM
Last Post: deanhystad

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020