Bank account
此页面需较新浏览器(支持 SharedArrayBuffer)。请升级 Chrome、Edge、Firefox 或 Safari 至最新版本。
此任务基于您尚未完成的课程。请先完成以下课程:
Python 基础 · Functions →
银行账户
一个很小的银行:按照一串指令操作,并且绝不让余额低于零。
"deposit 50".split() 按空格把字符串拆成 ["deposit", "50"]。金额仍然是文字,所以要用 int() 转换。在取款改变余额之前,先检查钱够不够;被拒绝的取款什么也不做。
难度 4/5 · 今日首次完成可获 280 金币及少量额外奖励
Write final_balance(actions). Each action is a string such as "deposit 50" 或 "withdraw 20". Start at 0, apply the actions in order, and refuse any withdrawal that would take the balance below 0. Return the final balance.
点击“运行”查看此处输出。