python中正实数怎么表示_对于Python中的正实数,“ math.floor(x)”和“ int(x)”会产生不同的结果吗?...

classRectangularRoom(object):"""

A RectangularRoom represents a rectangular region containing clean or dirty

tiles.

A room has a width and a height and contains (width * height) tiles. At any

particular time, each of these tiles is either clean or dirty.

"""def__init__(self,width,height):"""

Initializes a rectangular room with the specified width and height.

Initially, no tiles in the room have been cleaned.

width: an integer > 0

height: an integer > 0

"""self.width=width

self.height=height

self.room_coordinates=[]forminrange(self.width):forninrange(self.height):self.room_coordinates.append((m,n))self.cleaned=[]defcleanTileAtPosition(self,pos):"""

Mark the tile under the position POS as cleaned.

Assumes that POS represents a valid position inside this room.

pos: a Position

"""self.cleaned.append((int(pos.getX()),int(pos.getY())))defisTileCleaned(self,m,n):"""

Return True if the tile (m, n) has been cleaned.

Assumes that (m, n) represents a valid tile inside the room.

m: an integer

n: an integer

returns: True if (m, n) is cleaned, False otherwise

"""asserttype(m)==intandtype(n)==intreturn(m,n)inself.cleaneddefgetNumTiles(self):"""

Return the total number of tiles in the room.

returns: an integer

"""returnself.width*self.heightdefgetNumCleanedTiles(self):"""

Return the total number of clean tiles in the room.

returns: an integer

"""returnlen(self.cleaned)defgetRandomPosition(self):"""

Return a random position inside the room.

returns: a Position object.

"""returnPosition(random.randrange(0,self.width),random.randrange(0,self.height))defisPositionInRoom(self,pos):"""

Return True if pos is inside the room.

pos: a Position object.

returns: True if pos is in the room, False otherwise.

"""return(int(pos.getX()),int(pos.getY()))inself.room_coordinates

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值