python代写一般多少钱-python程序代写

Requirement

In this exercise, you’ll gain some practice designing and implementing a class, according to an English problem description. You will also practice using this class from another class, or, in other words, relating two classes through composition.

Note: completing this exercise requires Wednesday’s lecture content, so please don’t worry if you aren’t sure how to complete the exercise now. It’s a good idea to read through this handout, the starter code, and the sample tests early, so that you understand what it is you will accomplish.

Starter code

Save these files to your ex1 folder (inside exercises).

ex1.py [submit]

ex1_test.py

Task 1: A Car simulation

In this task, you’ll implement a basic car simulation, which tracks the positions and amounts of fuel of a set of cars in a city.

Super Duper is a new car ridesharing service which uses a computer system to manage its autonomous vehicles. The managing system contains a collection of cars, each uniquely identified by a string. The manager can add a new car to the collection, move a car, and get the current location of a car.

When a Super Duper car is created in the system, it is given an initial amount of fuel (specified individually per car), and starts at position (0,0) on the grid, representing the Super Duper headquarters. Cars can move to a new point (any integer coordinates are allowed) on the grid, but only move in horizontal and vertical lines. Cars cannot travel diagonally.

When cars move, they lose 1 unit of fuel per 1 unit of distance moved. If you try to move a car farther than it can go with its remaining fuel, the car stays in its original position, and does not use any fuel. (In other words, this method will "fail silently.” In general this is a bad practice, and we’ll explore better ways of handling situations like this later in the course.) Cars can move multiple times, as long as they have enough fuel.

In the starter code, we have created a SuperDuperManager class, which keeps track of all the cars in the Super Duper system. It is responsible for creating new cars, looking up a particular car and retrieving its position or fuel information, and directing cars to move to new locations. Read through the docstrings of the SuperDuperManager class and its methods.

The class has an instance attribute _cars which you must use to complete the Car simulation. (This is a "private” attribute, a concept we’ll cover in Friday’s lecture. Treat it like any other attribute for now.) Its methods correspond to the actions we just described, and you may not change their signatures.

You have two responsibilities:

Design and implement a Car class, which represents a single car according to the above description. We have begun this design for you, but it is your responsibility to complete it.

Implement the methods of the SuperDuperManager class to make use of your Car class.

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值