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
You're testing whether both conditions are true. Fill in the blank. | if a == b _____ c == d: | and | ^ *and *$ |
You're testing whether either condition is true. Fill in the blank. | if a == b _____ c == d: | or | ^ *or *$ |
Code a line that tests whether the variable city is "London" or "Tel Aviv." | if city == "London" or city == "Tel Aviv": | if `city `=`= `"London" `or `city `=`= `"Tel Aviv"`: | |
Code a line that tests whether the variable total is 10 or 20. | if total == 10 or total == 20: | if total == 10 or total == 20: | |
If the variable first_name is "Isaac" and the variable last_name is "Newton" display "Thanks!" | if first_name == "Isaac" and last_name == "Newton": print("Thanks!") | ^ *if first_name == •Isaac• and last_name == •Newton•:\n print\(•Thanks!•\) *$ | |
if x is smaller or equal to 5 or y is greater or equal to 10 display "yes". | if x <= 5 or y >= 10: print("yes") | ^ *if x <= 5 or y >= 10:\n print\(•yes•\) *$ | |
If the variable animal is "dog", "cat", or "mouse" display "mammal". | if animal == "dog" or animal == "cat" or animal == "mouse": print("mammal") | ^ *if animal == •dog• or animal == •cat• or animal == •mouse•:\n print\(•mammal•\) *$ | |
If the variable nationality is "UK" and either the variable age is under 21 or it's over 64 display "qualified" | if nationality == "UK" and (age < 21 or age > 64): print("qualified") | ^ *if nationality == •UK• and \(age < 21 or age > 64\):\n print\(•qualified•\) *$ | |
If the variable age is greater than or equal to 21 or the variable permission is "ok" display a message of your choice. | if age >= 21 or permission == "ok": print("Issue license") | ^ *if age >= 21 or permission == •ok•:\n print\(•.*•\) *$ | |
Code one line. If a equals b and c equals d, the test passes. Alternately, if e equals f or g equals h, the test passes. You could use elif to accomplish this, but don't. Use a combination of and, or, and parentheses. | if (a == b and c == d) or (e == f or g == h): | ^ *if \(a == b and c == d\) or [\(]?e == f or g == h[\)]?: *$ | |
| f97252db78 | ||
| ed321b9cc7 |