Homework for lesson 3.9-3.11
Problem 2.
Create an algorithm that uses selection and/or iteration that will represent one player’s complete turn.
During a turn, each player gets 4 attempts/chances to get the greatest number possible. During each attempt, the player will use a random number generator to select a random number from 1 to 10. After they have had 4 chances, their score is the greatest number they received from the random number generator, and their turn is over.
import random
numAttempts = []
i = 1
while i <= 4:
numAttempts.append(random.randint(1,10))
i = i +1
print("Attempts:", numAttempts)
sort(randomNumber)
print("Max Number:")
print(max(numAttempts))
Problem 3.
Create an algorithm that will allow the arrow to reach the gray square:
Repeat until reach gray square:
If canmoveForward
Move_Forward
else {
if canturnright{
turnright
}
if canturnleft{
turnleft
}
} }
Problem 8.
Explain why Binary Search is more efficient than Sequential Search
Binary search is more efficient because it moves exponentially while sequential search moves through the list one by one. Binary is able to search for half the numbers in a data set in one iteration, while sequential search has to go through every possibility.