You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this approach you define a [list][list] that contains Bob’s answers, and each condition is given a score.
19
19
The correct answer is selected from the list by using the score as the list index.
20
20
21
21
Python doesn't _enforce_ having real constant values,
22
-
but the `_ANSWERS` list is defined with all uppercase letters, which is the naming convention for a Python [constant][const].
22
+
but the `ANSWERS` list is defined with all uppercase letters, which is the naming convention for a Python [constant][const].
23
23
It indicates that the value is not intended to be changed.
24
-
Python also does not have real [private][private] variables,
25
-
but a leading underscore is the naming convention for indicating that a variable is not meant to be part of the public API.
26
-
It should be considered an implementation detail and subject to change without notice.
24
+
25
+
```exercism/note
26
+
`ANSWERS` could prevent item reassignment by being defined as a [tuple](https://realpython.com/python-lists-tuples/#python-tuples) instead of a list.
27
+
The items in a tuple cannot be changed, and the performance between a tuple and a list here is equivalent.
28
+
The entire `ANSWERS` tuple could still be reassigned to another tuple,
29
+
so uppercase letters would still be used to indicate that the `ANSWERS` tuple should not be changed.
30
+
```
27
31
28
32
The [`rstrip`][rstrip] method is applied to the input to eliminate any whitespace at the end of the input.
29
33
If the input has no characters left, it uses the [falsiness][falsiness] of an empty string with the [`not`][not] operator to return the response for saying nothing.
@@ -39,25 +43,24 @@ For example, `?` and `3` are not cased characters, as they do not change between
39
43
`a` and `z` are cased characters, since their lowercase form changes to `A` and ` Z` when uppercase.
40
44
```
41
45
42
-
If `isupper` is `True`, then `isShout` is given the value of `2`; otherwise, it is given the value of `0`.
46
+
If `isupper` is `True`, then `is_shout` is given the value of `2`; otherwise, it is given the value of `0`.
43
47
44
48
The [`endswith`][endswith] method is used to determine if the input ends with a question mark.
45
-
If the test for `endswith('?')` is `True`, then `isQuestion` is given the value of `1`; otherwise it is given the value of `0`.
49
+
If the test for `endswith('?')` is `True`, then `is_question` is given the value of `1`; otherwise it is given the value of `0`.
46
50
47
51
48
52
The response is selected from the list by the index like so
0 commit comments