#
# Copyright 2023, Ali Arya
# Anyone Can Code: Algorithmic Thinking
# Example 3p
#

def samples():
    #3.2p
    sum = 0
    for n in range(3): 	#assume 3 items
        price = int(input("Enter a price: "))
        sum += price
    print(sum)

    #3.3p
    factorial = 1
    n = int(input("Enter an integer number: "))
    for n in range(1,n):
        factorial *= n
    print(factorial)

    #3.4p
    sum = 0
    run = True
    while run==True: 	#assume 3 items
        price = int(input("Enter a price (0 to end): "))
        if price == 0:
             run = False
        sum += price
    print(sum)

    #3.5p
    names = ["ali", "john", "kim", "“jane"]
    numbers = ["555-1000", "555-2000", "555-3000", "555-4000"]
    search_name = input("Enter a name: ")
    for index in range( len(names) ):
        if names[index] == search_name:
            print( names[index]+" "+numbers[index] )

    #3.6p
    data_list = [1,4,6,9,13,25,67,99]
    x = int( input("enter the number to search: ") )
    low = 0 			
    high = len(data_list) - 1 
    searching = True
    while searching == True :
        mid = int((low + high)/2)
        print(mid)
        if x == data_list[mid]:
            print("found at ",mid)
            searching = False
        else:
            if low == high :
                print ("not found")
                searching = False
            if x > data_list[mid]: 	
                low = mid + 1
            else:
                high = mid - 1


    #3.7p
    unsorted = [6.5, 4.5, 6, 5, 7]
    sorted = []
    while len(unsorted)!=0:
        tallest = 0
        for i in range(len(unsorted)):  #Easier to use a for loop
            if unsorted[i] > unsorted[tallest]:
                tallest = i 
        sorted.append(unsorted[tallest])
        unsorted.remove(unsorted[tallest])
    print(unsorted)
    print(sorted)


