首页 » Python代做 » Python代写 | Assignment 07: Recursive Natural Number Verbalization [cse30s21]

Python代写 | Assignment 07: Recursive Natural Number Verbalization [cse30s21]

本次代写主要为Python递归相关的assignment

Background
File /srv/datasets/number_names.txt (also available via URL here) contains information on the (U.S. English) names we give
to different numeric values. Take a look at the file to get a feel for its contents.
For the purposes of this assignment, all values between 0 and 999 constitute one order of magnitude, and all other orders increase by a
factor of one thousand, e.g. thousands (103), millions (106), billions (1012), etc.

Assignment
You shall define a function named verbalize, in a module named verbalize.
1. The function shall accept one argument, assumed to be a nonnegative int, and shall return a list[str] containing
the verbal equivalent of  each order of magnitude  of the argument
1)
, as described in the following code and
docstring
2)
.
2. Make sure your module loads data from  number_names.txt  only once, regardless of how many
times verbalize() is called.
3. Make sure you solve this problem recursively: You are allowed one loop total in the module (for or while) without
penalty, which you will probably use for loading the contents of the number_names.txt file. Using recursion and
built-in functions like  next(),  reversed(),  sorted(), etc. will allow you to accomplish the rest without
loops. Each subsequent loop will reduce your grade by 20%.

def verbalize(value: int) -> list[str]:
“””
Returns a list of the verbalized orders of magnitude of a natural number, e.g.:

verbalize(0) –> [‘zero’]
verbalize(42) –> [‘forty-two’]
verbalize(101) –> [‘one hundred one’]
verbalize(9999) –> [‘nine thousand’, ‘nine hundred ninety-nine’]
verbalize(1234567) –>
[‘one million’, ‘two hundred thirty-four thousand’, ‘five hundred sixty-seven’]
“””
Since you are to solve this problem recursively, remember to think in terms of base cases (where you can immediately
return a result) and  recursive steps  (where you make recursive calls that change the arguments in order to proceed
toward a base case).
Hint: If the number is 123456, consider how you might verbalize the number of thousands:
1. Determining the count is simple division: 123456 // 1000 == 123
2. You know the order of magnitude is named thousand. If your function works correctly, you could make a
recursive call with 123 as the argument and receive the return value [‘one hundred twenty-three’].
3. The remaining verbalization should be of the value 123456 % 1000 == 456


程序辅导定制C/C++/JAVA/安卓/PYTHON/留学生/PHP/APP开发/MATLAB


本网站支持 Alipay WeChatPay PayPal等支付方式

E-mail: vipdue@outlook.com  微信号:vipnxx


如果您使用手机请先保存二维码,微信识别。如果用电脑,直接掏出手机果断扫描。

blank