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
Code line 3. | 1 if species == "cat": 2 print("Yep, it's cat.") 3 __________ 4 print("Nope, not cat.") | else: | ^ *else: *$ |
If the condition tested in line 1 fails, line 3 tests for a different condition. What keyword goes in the blank? | 1 if donut_condition == "fresh": 2   buy_score = 10 3 ____ donut_price == "low": 4 buy_score = 5 5 else: 6 buy_score = 0 | elif | ^ *elif *$ |
Code the next line that says what to do if the test fails. | if a == b: print("a equals b") | else: | else`: |
Code the next line. If a doesn't equal b, test whether c equals d. | if a == b: print("a equals b") | elif c == d: | elif c == d: |
Code four lines. If a equals b, c equals d. If the test fails, e equals f. | if a == b: c = d else: e = f | ^ *if a == b:\n c = d\nelse:\n e = f *$ | |
Code four lines. If a equals b, c equals d. If that test fails, then if e equals f, g equals h. | if a == b: c = d elif e == f: g = h | ^ *if a == b:\n c = d\nelif e == f:\n g = h *$ | |
What is the value of x? | if 2 + 3 == 4: x = 0 elif 2 - 1 == 1: x = 1 elif 3 + 3 == 6: x = 2 else: x = 3 | 1 - The first elif that passes stops the testing. | ^ *1 *$ |
Code the next two lines. If the test fails, test if a equals 2. If so, display "a equals 2". | if a == 1: print("a equals 1") | elif a == 2: print("a equals 2") | ^ *elif a == 2:\n print\(•a equals 2•\) *$ |
Code the next two lines. If the first two tests fail, display "failed". | if a == b: print("ok") elif c == d: print("ok") | else: print("failed") | ^ *else:\n print\(•failed•\) *$ |
Code six lines. If a equals b, display "ok". If not, then if c equals d, display "ok". If both tests fail, display "failed". | if a == b: print("ok") elif c == d: print("ok") else: print("failed") | ^ *if a == b:\n print\(•ok•\)\nelif c == d:\n print\(•ok•\)\nelse:\n print\(•failed•\) *$ | |
| c9c7999683 | ||
| e7b102876c |