• Jun 1, 2023 •CodeCatch
0 likes • 2 views
from colorama import init, Fore # Initialize colorama init() print(Fore.RED + "This text is in red color.") print(Fore.GREEN + "This text is in green color.") print(Fore.BLUE + "This text is in blue color.") # Reset colorama print(Fore.RESET + "This text is back to the default color.")
0 likes • 1 view
filename = "data.txt" with open(filename, "r") as file: file_contents = file.readlines() file_contents = [line.strip() for line in file_contents] print("File contents:") for line in file_contents: print(line)
• Nov 19, 2022 •CodeCatch
0 likes • 0 views
def print_x_pattern(size): i,j = 0,size - 1 while j >= 0 and i < size: initial_spaces = ' '*min(i,j) middle_spaces = ' '*(abs(i - j) - 1) final_spaces = ' '*(size - 1 - max(i,j)) if j == i: print(initial_spaces + '*' + final_spaces) else: print(initial_spaces + '*' + middle_spaces + '*' + final_spaces) i += 1 j -= 1 print_x_pattern(7)
• Mar 10, 2021 •Skrome
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
import string def caesar(text, shift, alphabets): def shift_alphabet(alphabet): return alphabet[shift:] + alphabet[:shift] shifted_alphabets = tuple(map(shift_alphabet, alphabets)) final_alphabet = "".join(alphabets) final_shifted_alphabet = "".join(shifted_alphabets) table = str.maketrans(final_alphabet, final_shifted_alphabet) return text.translate(table) plain_text = "Hey Skrome, welcome to CodeCatch" print(caesar(plain_text, 8, [string.ascii_lowercase, string.ascii_uppercase, string.punctuation]))
# Python program for implementation of Radix Sort # A function to do counting sort of arr[] according to # the digit represented by exp. def countingSort(arr, exp1): n = len(arr) # The output array elements that will have sorted arr output = [0] * (n) # initialize count array as 0 count = [0] * (10) # Store count of occurrences in count[] for i in range(0, n): index = (arr[i]/exp1) count[int((index)%10)] += 1 # Change count[i] so that count[i] now contains actual # position of this digit in output array for i in range(1,10): count[i] += count[i-1] # Build the output array i = n-1 while i>=0: index = (arr[i]/exp1) output[ count[ int((index)%10) ] - 1] = arr[i] count[int((index)%10)] -= 1 i -= 1 # Copying the output array to arr[], # so that arr now contains sorted numbers i = 0 for i in range(0,len(arr)): arr[i] = output[i] # Method to do Radix Sort def radixSort(arr): # Find the maximum number to know number of digits max1 = max(arr) # Do counting sort for every digit. Note that instead # of passing digit number, exp is passed. exp is 10^i # where i is current digit number exp = 1 while max1/exp > 0: countingSort(arr,exp) exp *= 10 # Driver code to test above arr = [ 170, 45, 75, 90, 802, 24, 2, 66] radixSort(arr) for i in range(len(arr)): print(arr[i]),