Wouldn't it be nice, Grant, if Homework was assigned with statements like: "Using only the features of the language covered up to chapter 3, meaning individual variables and lists of them and simple loops and only using the arithmetic built-in variable of +, -, % ... Solve this problem ...."
But there is an actual silly model and application to this homework assignment. Consider the kind of lock shown in the video (or skip the video) that has three or more wheels of sorts containing digits 0-9 and you rotate each wheel to a setting read down or across like 359. https://www.youtube.com/watch?v=BMeqkUiui20&feature=emb_logo If you are lazy, you can put the lock on your locker and move each wheel the same number of units in one direction. It is now securely locked and might show 682 or 026 and if nobody touches it and perturbs the setting, you can come back and perturb it back three units the other way (or continue seven more) and open it. See? A Very practical (albeit impractical) example of how this might be fractionally useful! I wrote a solution to the problem the student asked for that I chose not to share here that is one line of code including an embedded list comprehension to do the loop. If a student of mine in a beginning class offered me that solution, I would be fairly certain it was NOT their work, though, nor what I wanted them to do. Now the translate method, albeit elegant, is again not likely to be the one wanted as they probably have no idea that functionality exists. Heck, in some languages, they may not yet know looping constructs exist and be asked to use something like a GOTO! LOL! And, somewhere out there is something that implements the commonly (at least in the past) rot13 semi-cryptography of rotating the alphabet for fun and profit. You probably can load such a module and find a function that can rotate a numeric string by 3 or -3 and use that for a trivial solution. None of the above should be considered as having done the darn assignment as requested. However, if a student gave me a decent solution and ADDED that some search and research suggested other advanced methods they might use on the job later, sure, maybe they get extra credit. -----Original Message----- From: Python-list <python-list-bounces+avigross=verizon....@python.org> On Behalf Of Grant Edwards Sent: Saturday, February 20, 2021 12:31 PM To: python-list@python.org Subject: Re: Is there a way to subtract 3 from every digit of a number? On 2021-02-20, MRAB <pyt...@mrabarnett.plus.com> wrote: > Have a look at the 'translate' method of the 'str' class. That's very clever, but being too clever on homework assignemnts doesn't always get a good grade. If they've just studied iteration, the modulus operator, and int/str conversions, then I'd avise using the "dumb" method. -- Grant -- https://mail.python.org/mailman/listinfo/python-list -- https://mail.python.org/mailman/listinfo/python-list