OOP
Q1: vending Machine
In this question you'll create a vending machine that only outputs a single product and provides change when needed.
Create a class called
vendingMachine
that represents a vending machine for some product. AvendingMachine
object returns strings describing its interactions. Remember to match exactly the strings in the doctests -- including punctuation and spacing!Fill in the
vendingMachine
class, adding attributes and methods as appropriate, such that its behavior matches the following doctests:
According to the wiki, a vending machine is an automated machine that provides items to consumers after cash, or other forms of payment are inserted into the machine or otherwise made
这里说的 vending machine 其实也就是常见的自动售货机, 我们要为其写一个类实现应该有的功能. 这里的要求更为简单, 因为我们要实现的自动售货机只有一样东西可以卖, 而且每次只会买一件. 注意下面要实现函数的逻辑即可:
restock
, 补充商品, 这个比较简单add_funds
- 商品有库存的时候才会记住你付了多少钱
- 商品没有库存的时候直接退款给你
vend
- 商品有库存的时候
- 你支付的钱
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。
- 你支付的钱
- 商品有库存的时候