Title: [Numbers Concept Exercise]: Rethink/Redesign · Issue #2951 · exercism/python · GitHub
Open Graph Title: [Numbers Concept Exercise]: Rethink/Redesign · Issue #2951 · exercism/python
X Title: [Numbers Concept Exercise]: Rethink/Redesign · Issue #2951 · exercism/python
Description: Per issues #2946 , #2621 , #2835, #2804, #2591, and #2490 -- this exercise has gone through a lot of improvements and also complaints. Since multiple re-works and improvements have not succeeded, we have decided a complete re-design of t...
Open Graph Description: Per issues #2946 , #2621 , #2835, #2804, #2591, and #2490 -- this exercise has gone through a lot of improvements and also complaints. Since multiple re-works and improvements have not succeeded, w...
X Description: Per issues #2946 , #2621 , #2835, #2804, #2591, and #2490 -- this exercise has gone through a lot of improvements and also complaints. Since multiple re-works and improvements have not succeeded, w...
Opengraph URL: https://github.com/exercism/python/issues/2951
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"[Numbers Concept Exercise]: Rethink/Redesign ","articleBody":"Per issues #2946 , #2621 , #2835, #2804, #2591, and #2490 -- this exercise has gone through a lot of improvements and also complaints.\r\n\r\nSince multiple re-works and improvements have not succeeded, we have decided a complete re-design of the `Numbers` exercise is in order.\r\n\r\n**Concept docs can be retained, or revised as needed.** Design documents should be updated.\r\n\r\nOriginal specs for `Numbers` exercise are below: \r\n__________\r\n\r\nGoal\r\n--------\r\n\r\nThe goal of this exercise is to teach the basics of the`int` , `float` , and `complex` numeric types (`numbers`) in Python.\r\n\r\nLearning objectives\r\n-------------------\r\n\r\n* understand the difference between `int`, `float` and `complex` numbers in Python\r\n* understand that Python uses `j` to represent the square root of -1. appending `j` to a number defines it as _imaginary_. (**e.g.**`3j` is equivalent of `3(sqrt(-1))` -- **IF** Pythons math module allowed negative square roots...**it doesn't**).\r\n* understand that a decimal (`.`) preceeded or followed by a number creates a `float` _literal_\r\n* create an imaginary _literal_ via appending `j` to an `int` or `float` (**e.g.** 3.4j or 5j)\r\n* create a `float` by casting an `int` and an `int` by casting a `float`, using the `int()` and `float()` _constructors_.\r\n* create complex numbers by casting `int` and `float` to `complex` using the `complex()` _constructor_.\r\n* create a complex number by adding a `float` and an `imaginary` _literal_ (e.g. 3.0 + 6j)\r\n* understand when and how Python uses [arithmetic conversions](https://docs.python.org/3/reference/expressions.html#arithmetic-conversions) to apply arithmetic operators between these numeric types.\r\n* apply the [arithmetic operators](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) to each/between each of the number types (where applicable)\r\n* perform integer (floor) division and \"regular\" (float) division and see how they differ.\r\n* changing precision of a `float`, using `round(\u003cfloat\u003e, \u003cdigits\u003e)`\r\n\r\nOut of scope\r\n------------\r\n\r\n* Special values for `Infinity` and `NaN`\r\n* Special math functions for complex numbers contained in [cmath](https://docs.python.org/3.8/library/cmath.html)\r\n* Bitwise operations on `ints`\r\n* round numbers using `math.floor()` and `math.ceiling()`\r\n* Issues with precision limits \u0026 [`sys.float_info`](https://docs.python.org/3/library/sys.html#sys.float_info) -- but maybe we should note these in passing, or link to them in links.\r\n* Numpy and the numeric types defined by Numpy -- again, something for links/notes.\r\n* Checking strings to see if they are floats. This means any test input to this exercise should not require a student to (a) catch or raise an Exception if a non-float string is passed, or (b) check to see if the string is a float. Only pass valid float strings, i.e. `\"1.032\"`.\r\n\r\nConcepts\r\n--------\r\n\r\n* `numbers`\r\n* `arithmetic operations`\r\n\r\nPrerequisites\r\n-------------\r\n\r\n* `basics`\r\n\r\nResources to refer to\r\n---------------------\r\n\r\n* [Python numeric type documentation](https://docs.python.org/3/library/stdtypes.html#typesnumeric)\r\n* [Documentation for `int()` built in](https://docs.python.org/3/library/functions.html#int)\r\n* [Documentation for `complex()` built in](https://docs.python.org/3/library/functions.html#complex)\r\n* [Documentation for `float()` built in](https://docs.python.org/3/library/functions.html#float)\r\n* [Documentation for builtin function `round()`](https://docs.python.org/3/library/functions.html#round)\r\n* [Pythons Integer Implementation](https://rushter.com/blog/python-integer-implementation/#:~:text=Generally%2C%20In%20languages%20like%20C,are%20represented%20as%20a%20bignum.)\r\n* [Arithmetic conversions](https://docs.python.org/3/reference/expressions.html#arithmetic-conversions)\r\n* [Arithmetic Operations](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex) (see table and notes on the same page as numeric types.)\r\n* [Operator Precedence in Python](https://docs.python.org/3/reference/expressions.html#operator-precedence)\r\n\r\nHints\r\n-----\r\n\r\nHints can link to the builtin function docs mentioned above, with appropriate prompts.\r\n\r\nConcept Description\r\n-------------------\r\n\r\n(_a variant of this can be used for the `v3/languages/python/concepts/\u003cconcept\u003e/about.md` doc and this exercises `introduction.md` doc._)\r\n\r\nPython has three different types of built-in numbers: integers ([`int`](https://docs.python.org/3/library/functions.html#int)), floating-point ([`float`](https://docs.python.org/3/library/functions.html#float), and complex ([`complex`](https://docs.python.org/3/library/functions.html#complex)). Fractions ([`fractions.Fraction`](https://docs.python.org/3/library/fractions.html)) and Decimals ([`decimal.Decimal`](https://docs.python.org/3/library/decimal.html#module-decimal)) are also available via import from the standard library.\r\n\r\nWhole numbers (_including hex, octals and binary numbers_) without decimal places are identified as `ints`:\r\n\r\n```python\r\n#whole number\r\n\u003e\u003e\u003e 1234\r\n1234\r\n\u003e\u003e\u003e type(1234)\r\n\u003cclass 'int'\u003e\r\n\r\n\u003e\u003e\u003e -12\r\n-12\r\n\r\n#hex number\r\n\u003e\u003e\u003e 0x17\r\n23\r\n\u003e\u003e\u003e type(0x17)\r\n\u003cclass 'int'\u003e\r\n\r\n#octal number\r\n\u003e\u003e\u003e 0o446\r\n294\r\n\u003e\u003e\u003e type(0o446)\r\n\u003cclass 'int'\u003e\r\n\r\n#binary number\r\n\u003e\u003e\u003e 0b1100110\r\n102\r\n\u003e\u003e\u003e type(0b1100110)\r\n\u003cclass 'int'\u003e\r\n```\r\n\r\nNumbers containing a decimal point are identified as `floats`:\r\n\r\n```python\r\n\u003e\u003e\u003e 3.45\r\n3.45\r\n\u003e\u003e\u003e type(3.45)\r\n\u003cclass 'float'\u003e\r\n\r\nAppending `j` or `J` to a number creates a _imaginary number_ -- a `complex` number with a zero real part. Integers or floats can then be added to an imaginary number to create a `complex` number with both real and imaginary parts:\r\n\r\n\u003e\u003e\u003e 3j\r\n3j\r\n\u003e\u003e\u003e type(3j)\r\n\u003cclass 'complex'\u003e\r\n\r\n\u003e\u003e\u003e 3.5+4j\r\n(3.5+4j)\r\n```\r\n\r\n### Arithmetic\r\n\r\nPython fully supports arithmetic between these different number types, and will convert narrower numbers to match their less narrow counterparts when used with binary arithmetic operators (`+`, `-`, `*`, `/`, and `%`). `ints` are narrower than `floats`, which are considered narrower than `complex`. Comparisons between different number types behaves as as if the _exact_ values of those numbers were being compared:\r\n\r\n```python\r\n#the int is widened to a float here, and a float is returned\r\n\u003e\u003e\u003e 3 + 4.0\r\n7.0\r\n\r\n#the int is widened to a complex number, and a complex number is returned\r\n\u003e\u003e\u003e 6/(3+2j)\r\n(2+2j)\r\n\r\n#division always returns a float, even if integers are used\r\n\u003e\u003e\u003e 6/2\r\n3.0\r\n\r\n#if an int result is needed, you can use floor division to truncate the result\r\n\u003e\u003e\u003e 6//2\r\n3\r\n\r\n#when comparing, exact values are used\r\n\u003e\u003e\u003e 23 == 0x17\r\nTrue\r\n\r\n\u003e\u003e\u003e 0b10111 \\== 0x17\r\nTrue\r\n\r\n\u003e\u003e\u003e 6 == (6+0j)\r\nTrue\r\n```\r\n\r\nAll numbers (except complex) support the same general [arithmetic operations](https://docs.python.org/3/library/stdtypes.html#numeric-types-int-float-complex), evaluated according to [operator precedence](https://docs.python.org/3/reference/expressions.html#operator-precedence).\r\n\r\n\r\n### Precision \u0026 Representation\r\n\r\nIntegers in Python have [arbitrary precision](https://en.wikipedia.org/wiki/Arbitrary-precision_arithmetic) -- the amount of digits is limited only by the available memory of the host system.\r\n\r\nFloating point numbers are usually implemented using a `double` in C (_15 decimal places of precision_), but will vary in representation based on the host system. Complex numbers have a `real` and an `imaginary` part, both of which are represented by floating point numbers.\r\n\r\nFor a more detailed discussion of the issues and limitations of floating point arithmetic, take a look at [The Python Tutorial](https://docs.python.org/3.9/tutorial/floatingpoint.html).\r\n\r\nImplementing\r\n------------\r\n\r\nTests should be written using `unittest.TestCase`, and the test file named `numbers_test.py`.\r\n\r\nCode in the `.meta/example.py` file should only use syntax \u0026 concepts introduced in this exercise or one of its prerequisites. \r\nPlease do not use comprehensions, generator expressions, or other syntax not previously covered. Please also follow [PEP8](https://www.python.org/dev/peps/pep-0008/) guidelines.\r\n\r\nHelp\r\n----\r\n\r\nIf you have any questions while implementing the exercise, please post the questions as comments in this issue.","author":{"url":"https://github.com/BethanyG","@type":"Person","name":"BethanyG"},"datePublished":"2022-02-21T18:48:36.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":16},"url":"https://github.com/2951/python/issues/2951"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f75fe1cd-69bb-a0e4-dd35-c409dc061dd3 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9D76:1D9151:E8A2A0:135BE2F:69698DF4 |
| html-safe-nonce | 86d34f35ab21a65279c8c693d05e1c2d8a46e941d66d8721df59468b5bb4e5d8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5RDc2OjFEOTE1MTpFOEEyQTA6MTM1QkUyRjo2OTY5OERGNCIsInZpc2l0b3JfaWQiOiIyMjIyNjM4NzIxNDE3NTc5NDAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | b6dec7ed2d8e147e66a54fa73f71c5a012b748934ee842ec564a30e6cdf3feb1 |
| hovercard-subject-tag | issue:1146128295 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/exercism/python/2951/issue_layout |
| twitter:image | https://opengraph.githubassets.com/f6ac36a2e8a5f6eedf1b045c0d88e3e4a04fba862a85900a031b6b9689637be9/exercism/python/issues/2951 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/f6ac36a2e8a5f6eedf1b045c0d88e3e4a04fba862a85900a031b6b9689637be9/exercism/python/issues/2951 |
| og:image:alt | Per issues #2946 , #2621 , #2835, #2804, #2591, and #2490 -- this exercise has gone through a lot of improvements and also complaints. Since multiple re-works and improvements have not succeeded, w... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | BethanyG |
| hostname | github.com |
| expected-hostname | github.com |
| None | 3542e147982176a7ebaa23dfb559c8af16f721c03ec560c68c56b64a0f35e751 |
| turbo-cache-control | no-preview |
| go-import | github.com/exercism/python git https://github.com/exercism/python.git |
| octolytics-dimension-user_id | 5624255 |
| octolytics-dimension-user_login | exercism |
| octolytics-dimension-repository_id | 17274389 |
| octolytics-dimension-repository_nwo | exercism/python |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 17274389 |
| octolytics-dimension-repository_network_root_nwo | exercism/python |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | af80af7cc9e3de9c336f18b208a600950a3c187c |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width