1
2
3
4
5
6
7
8
9
10
11
12
To practice on your own, or to check code you believe shouldn't have been scored as incorrect, go to Trinket.
Post a review on Amazon for the paperback or the Kindle edition.
Email me to give me a compliment, complaint, or correction. I'll respond.
0,1,2,3,4,5,6,7,8,9,10,11
0
0
0
0
Translate this into nested ifs: | if a == b and c == d: | if a == b: if c == d: | ^ *if a == b:\n if c == d: *$ |
Translate this into a four-line if and elif: | if a == b or c == d: print("ok") | if a == b: print("ok") elif c == d: print("ok") | ^ *if a == b:\n print\(•ok•\)\nelif c == d:\n print\(•ok•\) *$ |
If both the first and second test don't pass, something else happens. Write the next line. | if a == b: if c == d: e = f | else: | else: |
Rewrite the second line so it's legal. | if a == b: if c == d g = h | if c == d: | if c == d: |
If a equals b and if c equals d, e equals f. Code all three lines using nesting. | if a == b: if c == d: e = f | ^ *if a == b:\n if c == d:\n e = f *$ | |
Translate this into two lines with the second line nested: | if a == b and c == d: | if a == b: if c == d: | ^ *if a == b:\n if c == d: *$ |
Translate this into three lines using nesting: | if a == 1 and b == 2 and c == 3: | if a == 1: if b == 2: if c == 3: | ^ *if a == 1:\n if b == 2:\n if c == 3: *$ |
Translate this into four lines using nesting: | if a == 1 and b == 2 and c == 3: d = 6 | if a == 1: if b == 2: if c == 3: d = 6 | ^ *if a == 1:\n if b == 2:\n if c == 3:\n d = 6 *$ |
Translate this using nesting. | if a == b and (c == d or e == f): g = h | if a == b: if c == d: g = h elif e == f: g = h | ^ *if a == b:\n if c == d:\n g = h\n elif e == f:\n g = h *$ |
If the first test succeeds but the nested test fails, code a second nested test for whether a is not equal to b. Don't forget to indent it. | if c == d: if x == y: g = h | elif a != b: | ^ * elif a != b: *$ |
| ed776503d9 | ||
| 9e3b5c6872 |