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
Reply
#6
While that sounds possible, it could also be that the OP simply isn't very familiar with English.
Feel like you're not getting the answers you want? Checkout the help/rules for things like what to include/not include in a post, how to use code tags, how to ask smart questions, and more.

Pro-tip - there's an inverse correlation between the number of lines of code posted and my enthusiasm for helping with a question :)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  VS Code debugger using wrong Python environment topfox 0 186 Jun-09-2021, 10:01 AM
Last Post: topfox
  Whats wrong with the elif? inunanimous93 3 516 Nov-30-2020, 03:58 AM
Last Post: deanhystad
  What is wrong with my code??? MrLeads 15 1,226 Sep-16-2020, 02:00 PM
Last Post: MrLeads
  Can somebody check what is wrong with my code? hplus_liberation 4 764 Sep-16-2020, 05:52 AM
Last Post: perfringo
  what is wrong with this code? bitcoin10mil 2 579 Aug-23-2020, 09:12 AM
Last Post: DPaul
  Whats Wrong!? rjay81 3 684 May-13-2020, 08:02 PM
Last Post: rjay81
  Can u see this code and tell whats wrong with it? AhmadKamal 14 1,783 Apr-29-2020, 11:09 AM
Last Post: jefsummers
  Manipulating index value, what is wrong with this code? Emun 1 688 Feb-05-2020, 07:18 AM
Last Post: perfringo
  tell me what's wrong with my code? codingisannoyingaf 6 1,259 Jan-02-2020, 11:28 AM
Last Post: adaomacarl
  What is wrong with my chemistry code? mimimycin 9 1,379 Dec-30-2019, 06:43 PM
Last Post: mimimycin

Forum Jump:

User Panel Messages

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