Defining Algorithms

  • An algorithm is a process or set of rules to be followed through CODE
  • can be written in differeent ways and still accomplish the tasks
  • appear similar may yeild different results
  • conditionals can be written the same as boolean expressions

Conditionals vs Booleans

  • condition is a booleans expresson when an expression outputs either tru or false
  • boolean values can only ever hold true or false

3.8 part 3

Binary Search

  • determine the number of iterations to find value uin data set
  • Binary search: search algoristhm that finds the position of a target value w/in an array
  • an algorithm for iterating to find a value inside adata set
  • starts in the middle of a data set of numbers and eliminates 1/2 the data, process is repeated until value is found
print("choose value for x")

varx=int(input("Enter any positive Integer"))

if (varx %2 == 0):
    print("the number is even")

else:
    print("the number is odd")
# Run this cell to see how it works
import random # allows the program to generate random numbers

score = 0
iterate = 0

while (iterate < 3):
    var1 = random.randint(1, 20)
    if (var1 >= score):
        score = var1
    iterate = iterate + 1
else:
    print(f"Score: {score}")
Score: {score}