脚本不会打印输出

时间:2018-09-20 17:41:06

标签: python list

此代码模拟了位于5楼的电梯,人们进入其中并选择了预定的楼层。该代码工作正常,但是当我要求用户输入时,它不会打印输出。

就像这里

class Elevator:
    def __init__(self,initial= 5,floors=35,speed=10):
        self.__initial_value = initial
        self.__current_value = initial
        self.__number_floors = floors
        self.__speed = speed
    def set_requests(self,floor_requests):
        print("="*20 , 'New Request', "="*20)
        error, valid = self.check_requests(floor_requests)
        if len(error) > 0:
            print("Wrong in the series of floor requests: ", error)
        if len(valid) != 0:
            self.__requests = valid
            self.movement()
        print()
    def movement(self):
        self.__requests.sort()
        print('valid requests : ', self.__requests)
        print('Starting ...\n')
        for floor in self.__requests:
            if floor != self.__current_value:
                print("Current floor of the elevator: ", str(self.__current_value))
                print("next destination of the elevator: ", str(floor))
                step = abs(self.__current_value - floor)
                print("the floors left to arrive at the destination: ", str(step))
                print("time left to arrive at the destination: ", str(step*self.__speed) ,'second')
            print("Exit the client on the floor: ",floor)
            self.__current_value = floor
    def check_requests(self,requests):
        error = []
        valid_requests = []
        for request in requests:
            if 0 > request or request > self.__number_floors-1:
                error.append(request)
            else:
                valid_requests.append(request)
        return error,valid_requests



e = Elevator()
e.set_requests = list()
clients = input("Enter the number of clients: ")
for i in range(int(clients)):
    n = input("destinations: ")
    e.set_requests.append(int(n))

但是当我设置一些示例时,它工作正常:

class Elevator:
    def __init__(self,initial= 5,floors=35,speed=10):
        self.__initial_value = initial
        self.__current_value = initial
        self.__number_floors = floors
        self.__speed = speed
    def set_requests(self,floor_requests):
        print("="*20 , 'New Request', "="*20)
        error, valid = self.check_requests(floor_requests)
        if len(error) > 0:
            print("Wrong in the series of floor requests: ", error)
        if len(valid) != 0:
            self.__requests = valid
            self.movement()
        print()
    def movement(self):
        self.__requests.sort()
        print('valid requests : ', self.__requests)
        print('Starting ...\n')
        for floor in self.__requests:
            if floor != self.__current_value:
                print("Current floor of the elevator: ", str(self.__current_value))
                print("next destination of the elevator: ", str(floor))
                step = abs(self.__current_value - floor)
                print("the floors left to arrive at the destination: ", str(step))
                print("time left to arrive at the destination: ", str(step*self.__speed) ,'second')
            print("Exit the client on the floor: ",floor)
            self.__current_value = floor
    def check_requests(self,requests):
        error = []
        valid_requests = []
        for request in requests:
            if 0 > request or request > self.__number_floors-1:
                error.append(request)
            else:
                valid_requests.append(request)
        return error,valid_requests



e = Elevator()
e.set_requests([25])
e.set_requests([60])
e.set_requests([17])

卡在我应该做的事情上。谁能帮我吗?

1 个答案:

答案 0 :(得分:0)

您有 { "Effect": "Allow", "Action": [ "s3:GetBucketLocation", "s3:GetObject", "s3:ListBucket", "s3:ListBucketMultipartUploads", "s3:ListMultipartUploadParts", "s3:AbortMultipartUpload", "s3:CreateBucket", "s3:PutObject" ], "Resource": [ "arn:aws:s3:::your-source-data-bucket-name*" ] } 个您刚刚错过的setter,只是向您的班级添加了一个getter函数!

那应该可以解决问题!

通过使用get_request的方式,应该使用print并打印结果...