### Assignment
Students in primary school often arrange arithmetic problems vertically to make them easier to solve. For example, "235 + 52" becomes:
```
235
+ 52
-----
```
Create a function that receives a list of strings that are arithmetic problems and returns the problems arranged vertically and side-by-side. The function should optionally take a second argument. When the second argument is set to `True`, the answers should be displayed.
### For example
Function Call:
```py
arithmetic_arranger(["32 + 698", "3801 - 2", "45 + 43", "123 + 49"])
```
Output:
```
32 3801 45 123
+ 698 - 2 + 43 + 49
----- ------ ---- -----
```
Function Call:
```py
arithmetic_arranger(["32 + 8", "1 - 3801", "9999 + 9999", "523 - 49"], True)
```
Output:
```
32 1 9999 523
+ 8 - 3801 + 9999 - 49
---- ------ ------ -----
40 -3800 19998 474
```
### Rules
The function will return the correct conversion if the supplied problems are properly formatted, otherwise, it will **return** a **string** that describes an error that is meaningful to the user.
* Situations that will return an error:
* If there are **too many problems** supplied to the function. The limit is **five**, anything more will return:
`Error: Too many problems.`
* The appropriate operators the function will accept are **addition** and **subtraction**. Multiplication and division will return an error. Other operators not mentioned in this bullet point will not need to be tested. The error returned will be:
`Error: Operator must be '+' or '-'.`
* Each number (operand) should only contain digits. Otherwise, the function will return:
`Error: Numbers must only contain digits.`
* Each operand (aka number on each side of the operator) has a max of four digits in width. Otherwise, the error string returned will be:
`Error: Numbers cannot be more than four digits.`
* If the user supplied the correct format of problems, the conversion you return will follow these rules:
* There should be a single space between the operator and the longest of the two operands, the operator will be on the same line as the second operand, both operands will be in the same order as provided (the first will be the top one and the second will be the bottom.
* Numbers should be right-aligned.
* There should be four spaces between each problem.
* There should be dashes at the bottom of each problem. The dashes should run along the entire length of each problem individually. (The example above shows what this should look like.)
### Development
Write your code in `arithmetic_arranger.py`. For development, you can use `main.py` to test your `arithmetic_arranger()` function. Click the "run" button and `main.py` will run.
### Testing
The unit tests for this project are in `test_module.py`. We are running the tests from `test_module.py` in `main.py` for your convenience. The tests will run automatically whenever you hit the "run" button. Alternatively you may run the tests by inputting `pytest` in the console.
### Submitting
Copy your project's URL and submit it to freeCodeCamp.
没有合适的资源?快使用搜索试试~ 我知道了~
freeCodeCamp:使用Python项目进行科学计算[算术格式化解决方案]-源码
共5个文件
py:2个
toml:1个
replit:1个
需积分: 2 2 下载量 174 浏览量
2022-02-07
06:28:25
上传
评论
收藏 3KB ZIP 举报
温馨提示
把下载的文件打开复制进网页对应的python文件代码里再提交即可通过
资源详情
资源评论
资源推荐
收起资源包目录
boilerplate-arithmetic-formatter-2.zip (5个子文件)
pyproject.toml 311B
README.md 3KB
.replit 43B
main.py 285B
arithmetic_arranger.py 3KB
共 5 条
- 1
「已注销」
- 粉丝: 0
- 资源: 5
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- vscode-1.64.1.tar源码文件
- vscode-1.64.0.tar源码文件
- vscode-1.52.0.tar源码文件
- Music-Player +PlayerActivity+ rockplayer+ SeeJoPlayer 播放器JAVA源码
- vscode-1.46.0.tar源码文件
- 最近很火植物大战僵尸杂交版2.08苹果+安卓+PC+防闪退工具V2+修改工具+高清工具+通关存档整合包更新
- 超级好用的截图工具PixPin,可录制Gif图
- Screenshot_2024-05-21-17-06-42-64_2332cb9b27b851b548ba47a91682926c.jpg
- 毕业设计参考 - 基于树莓派、OpenCV及Python的人脸识别
- node-v18.20.2-linux-arm64
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功
评论0