• Mar 10, 2021 •Skrome
0 likes • 1 view
color2 = (60, 74, 172) color1 = (19, 28, 87) percent = 1.0 for i in range(101): resultRed = round(color1[0] + percent * (color2[0] - color1[0])) resultGreen = round(color1[1] + percent * (color2[1] - color1[1])) resultBlue = round(color1[2] + percent * (color2[2] - color1[2])) print((resultRed, resultGreen, resultBlue)) percent -= 0.01
• Nov 19, 2022 •CodeCatch
0 likes • 4 views
""" Binary Search Algorithm ---------------------------------------- """ #iterative implementation of binary search in Python def binary_search(a_list, item): """Performs iterative binary search to find the position of an integer in a given, sorted, list. a_list -- sorted list of integers item -- integer you are searching for the position of """ first = 0 last = len(a_list) - 1 while first <= last: i = (first + last) / 2 if a_list[i] == item: return ' found at position '.format(item=item, i=i) elif a_list[i] > item: last = i - 1 elif a_list[i] < item: first = i + 1 else: return ' not found in the list'.format(item=item) #recursive implementation of binary search in Python def binary_search_recursive(a_list, item): """Performs recursive binary search of an integer in a given, sorted, list. a_list -- sorted list of integers item -- integer you are searching for the position of """ first = 0 last = len(a_list) - 1 if len(a_list) == 0: return ' was not found in the list'.format(item=item) else: i = (first + last) // 2 if item == a_list[i]: return ' found'.format(item=item) else: if a_list[i] < item: return binary_search_recursive(a_list[i+1:], item) else: return binary_search_recursive(a_list[:i], item)
• Feb 26, 2023 •wabdelh
0 likes • 0 views
#84 48 13 20 61 20 33 97 34 45 6 63 71 66 24 57 92 74 6 25 51 86 48 15 64 55 77 30 56 53 37 99 9 59 57 61 30 97 50 63 59 62 39 32 34 4 96 51 8 86 10 62 16 55 81 88 71 25 27 78 79 88 92 50 16 8 67 82 67 37 84 3 33 4 78 98 39 64 98 94 24 82 45 3 53 74 96 9 10 94 13 79 15 27 56 66 32 81 77 # xor a list of integers to find the lonely integer res = a[0] for i in range(1,len(a)): res = res ^ a[i]
def print_pyramid_pattern(n): # outer loop to handle number of rows # n in this case for i in range(0, n): # inner loop to handle number of columns # values changing acc. to outer loop for j in range(0, i+1): # printing stars print("* ",end="") # ending line after each row print("\r") print_pyramid_pattern(10)
0 likes • 3 views
def clamp_number(num, a, b): return max(min(num, max(a, b)), min(a, b)) clamp_number(2, 3, 5) # 3 clamp_number(1, -1, -5) # -1
• May 31, 2023 •CodeCatch
# Prompt user for base and height base = float(input("Enter the base of the triangle: ")) height = float(input("Enter the height of the triangle: ")) # Calculate the area area = (base * height) / 2 # Display the result print("The area of the triangle is:", area)