Sections 9-11 Hacks
The Section 9-11 Hacks
Hack #1
if (isCold or isRaining) {
stayInside <-- True
}
else {
stayInside <-- False
}
Hack #2
import random
# This is necessary, as this program is supposed to utilize a random number generator to select a random number from 1 to 10.
attemptCount = []
i = 1
# Initial attempt count
while i <= 4:
attemptCount.append(random.randint(1,10))
i = i + 1
print("Attempts: ", attemptCount)
print("")
print("Your FINAL score is:", max(attemptCount))
Hack #3
{
if MoveForwardPossible {
moveForward
}
elif {
MoveRightPossible {
moveRight
}
}
elif {
MoveLeftPossible {
moveLeft
}
}
}
Hack #4
Images shown in post (refer to post)
Hack #5
To find 69, the list would be iterated through until the number 69 is found. This would take 7 iterations.
Using a binary search instead, this process would be much more efficient. The search would start from the middle index, then going to the first and last index and dividing by two. This process goes through until the number 69 is found.
Hack #6
Images shown in post (refer to post)
Hack #7
["Market","Walmart","store","Target","Ralphs"]
Hack #8
Binary search is much more efficient than a sequential search. This is because sequential searches move one by one, iterating through each object. Binary searches search the list of data exponentially, which takes a much shorter time.
Hack #9
In this situation, you are searching for 11. The middle index would be 16, which is where you start, and then you would do 3 + 5 all divided by two, which gives 4. The next index would be at 11, which is what we are looking for.
Images shown in post (refer to post)