3.9 and 3.11 Hacks
Unit 3.9.1 Hacks
1) It is important to know that algorithms can have different results even though they look the same because it is good to know different ways to accomplish the same thing. This can help visualized the steps and process to make the coding process more efficient.
In addition algorithms having different outputs but similar code is important to know when trouble shooting code in order to find out what is wrong.
isTeams = False
isScore = True
if isTeams == True:
print("You didn't win the game yet!")
else:
if isScore == True:
print("You won!")
else:
print("You didn't win the game yet!")
isTeams = False
isScore = True
winGame = not(isTeams) and isScore
if winGame == False:
print("You didn't win the game yet!")
if winGame == True:
print("You won the game!")
isRaining = True
temp = 70
if isRaining == True and temp < 45:
print("Wear multiple layers.")
else:
if temp > 45:
print("Wear whatever u want")
else:
if isRaining == False:
bro = input("is it sunny or snowing?")
else:
print("what is the weather like?")
import random
#sets variables for the game
num_guesses = 0
user_guess = -1
upper_bound = 100
lower_bound = 0
#generates a random number
number = random.randint(0,100)
# print(number) #for testing purposes
print(f"I'm thinking of a number between 0 and 100.")
#Write a function that gets a guess from the user using input()
def guess():
num = input("What number?")
#add something here
return num #add something here
#Change the print statements to give feedback on whether the player guessed too high or too low
def search(number, guess):
global lower_bound, upper_bound
if int(guess) < int(number):
print("Too low") #change this
lower_bound = guess
return lower_bound, upper_bound
elif int(guess) > int(number):
print("Too high") #change this
upper_bound = guess
return lower_bound, upper_bound
else:
upper_bound, lower_bound = guess, guess
return lower_bound, upper_bound
while user_guess != number:
user_guess = guess()
num_guesses += 1
print(f"You guessed {user_guess}.")
lower_bound, upper_bound = search(number, user_guess)
if int(upper_bound) == int(number):
break
else:
print(f"Guess a number between {lower_bound} and {upper_bound}.")
print(f"You guessed the number in {num_guesses} guesses!")
num = random.randint(0, 100)
#print(num)
var = False
while var == False:
put = input("I am thinking of a number from between 1-100.")
print(put)
if num < int(put):
print("Guess a lower number")
if int(put) < num:
print("Guess a higher number")
if num == int(put):
print("Good Job, You guessed the right number!")
var = True
index = [12, 14, 43, 57, 79, 80, 99]
index[x].sort()
mid = int(len(index) / 2)
print(mid)
print(index[mid])
index =[92, 43, 74, 66, 30, 12, 1]
index.sort()
mid = int(len(index) / 2)
print(mid)
print(index[mid])
index = [7, 13, 96, 111, 33, 84, 60]
index.sort()
mid = int(len(index) / 2)
print(mid)
print(index[mid])
2) Set one : 80
Set two: 74
Set three: 96
3) C, because it is unsorted
def fib(num): # define function parameter = num
if num == 0 or num == 1: # if num is equal to 1 or 0, then just return them
return num
return fib(num - 1) + fib(num - 2) # else add the numbers 1 and 2 before the original one
for i in range(20): #loop 20 times
print(fib(i))