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
Rewrite this line so it's valid: | if species = "cat": | You need a double equal sign: if species == "cat": | ^ *if species == •cat•: *$ |
Rewrite this line so it's valid: | if species == "cat" | You need a colon at the end: if species == "cat": | ^ *if species == •cat•: *$ |
Write the first line of an if statement that tests whether species is "cat" | if species == "cat": | if `species `=`= `"`cat`"`: | |
Code the first line of an if statement that tests whether x has the same value as y | if x == y: | if x == y: | |
Code the first line of an if statement that tests whether one variable is the same as another. Make up the variable names. | if current_town == birth_town: | ^ *if [a-zA-Z_][a-zA-Z0-9_]* == [a-zA-Z_][a-zA-Z0-9_]*: *$ | |
Below, I've coded the first line of an if statement. Code the second line. The second line tells Python to display the string "OK". Don't forget to indent the second line. | if current_address == previous_address: | print("OK") | ^ * print\(•OK•\) *$ |
On line 1, test whether a has the same value as b. On line 2, write that c equals d. Don't forget to indent the second line. | if a == b: c = d | ^ *if a == b:\n c = d *$ | |
If total has the value of 100, tax has the value of 2. Code both lines. Don't forget to indent the second line. | if total == 100: tax = 2 | ^ *if total == 100:\n tax = 2 *$ | |
If first_name is "Sherlock" last_name is "Holmes" and pal is "Watson". Code all three lines. | if first_name == "Sherlock": last_name = "Holmes" pal = "Watson" | ^ *if first_name == •Sherlock•:\n last_name = •Holmes•\n pal = •Watson• *$ | |
If you_won is "yes" tell Python to display "congrats". Code both lines. | if you_won == "yes": print("congrats") | ^ *if you_won == •yes•:\n print\(•congrats•\) *$ | |
| c097da8c02 | ||
| 1cdeefa3e9 |