 ## ← Equivalent Expressions Solution - Intro to Computer Science

• 2 Followers
• 33 Lines

### Get Embed Code x Embed video Use the following code to embed this video. See our usage guide for more details on embedding. Paste this in your document somewhere (closest to the closing body tag is preferable): ```<script type="text/javascript" src='https://amara.org/embedder-iframe'></script> ``` Paste this inside your HTML body, where you want to include the widget: ```<div class="amara-embed" data-url="http://www.youtube.com/watch?v=TRuWp6uRBKI" data-team="udacity"></div> ``` 2 Languages

• English [en] original
• Japanese [ja]

Showing Revision 5 created 05/25/2016 by Udacity Robot.

1. So the answer is, only the second and the third
2. are equivalent. This is a little surprising. This was kind
3. of a tricky question. So the reason the first one
4. is not, if x is seven or greater, well, then seven
5. mod seven has the value zero. That's not the same
6. as the x that we started with. And that's the
7. case also if we have eight. Eight module seven has
8. the value one. Which is different from what we started with.
9. When the modulo is greater than the possible value of
10. x, and we said, x could be only between zero and
11. 10, well, then, the result is always the same as
12. x. The third question, when we map x to its character
13. value, and then we take the order of that, we'll
14. char an order inverses, so that's equivalent. You would think that
15. would in the other direction and the reason it doesn't is
16. because the input to ord must be a one letter string.
17. If the input's not a single character, then ord produces
18. an error. So let's see that in the Python interpreter, if
19. we print the result of ord where the input is a
20. number and we said x was a number between zero and
21. three. Well, that gives us an error. And it gives an
22. error, because ord expects a string of length one, but the
23. input was an integer. There is a function that allows us
24. to turn numbers into strings. And that's the str function that
25. takes a number and gives us a string corresponding
26. to that number. So let's see what str of three
27. gives us, that will give us the string three,
28. we can't see in output here that it is actually
29. a string, but it is a string, and we
30. can actually use order on the result there. When we
31. run this, what we get is 51, not the
32. three that we passed in and that's because the ord
33. of the character three is 51.