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
What is the keyword in a loop that keeps repeating as long as some condition is met? | while | ^ *while *$ | |
Code the first line of a while loop that keeps repeating as long as x equals 1. | while x == 1: | ^ *while x == 1\: *$ | |
Code the first line of a while loop that keeps repeating as long as x doesn't equal "Hanoi". | while x != "Hanoi": | while `x `!`= `"`Hanoi`"`: | |
Code the line that must precede this line. | while name != "Hanoi": | name = "" | name = "" |
As long as x doesn't equal 99, display x, then increment it by 1 using the concise way to increment. | while x != 99: print(x) x += 1 |
^ *while x != 99:\n print\(x\)\n x \+= 1 *$ | |
As long a one integer variable is less than another integer variable, increment the first variable by 3 using the concise way to increment. Make up the variable names. | while x < y: x += 3 |
^ *while ([a-zA-Z_][a-zA-Z0-9_]*) < [a-zA-Z_][a-zA-Z0-9_]*:\n \1 \+= 3 *$ | |
Code a function that has two parameters that are lists. As long as the first list is shorter than the second list, append an element, "empty", to the first list. Make up the names of the function and variables. | def even_out(first_list, second_list): while len(first_list) < len(second_list): first_list.append("empty") |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n while len\(\1\) < len\(\2\):\n \1\.append\(•empty•\) *$ | |
Code a function with three parameters that hold integers passed to them by the calling code. As long as the total of the first two variables is greater than the third variable, subtract half of the third variable from the first variable using the concise way to subtract. Make everything up. | def reduce(x, y, z): while x + y > z: x -= z / 2 |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*), ([a-zA-Z_][a-zA-Z0-9_]*)\):\n while \1 \+ \2 > \3:\n \1 -= \3 \/ 2 *$ | |
Code a function that asks for the user's input. Keep asking until the user enters "You're right" Make up the name of the function, the text that prompts the user, and the variable that holds the user's input. Remember to declare the variable as an empty string in line 2. | def get_validation(): response = "" while response != "You're right": response = input("Tell me I'm right: ") |
^ *def [a-zA-Z_][a-zA-Z0-9_]*\(\):\n ([a-zA-Z_][a-zA-Z0-9_]*) = ••\n while \1 != •You◘re right•:\n \1 = input\(•.+•\) *$ | |
As long as a variable holding an integer is less than the value of another variable, run a for loop that loops through all the elements of a list and adds each element of the list to the first variable. Use the concise approach to increment the first variable. Make everything up. | while first_number < second_number: for number in number_list: first_number += number |
^ *while ([a-zA-Z_][a-zA-Z0-9_]*) < [a-zA-Z_][a-zA-Z0-9_]*:\n for ([a-zA-Z_][a-zA-Z0-9_]*) in [a-zA-Z_][a-zA-Z0-9_]*:\n \1 \+= \2 *$ | |
|
0b3460f76c | ||
|
1cb4f569e0 |