• Nov 19, 2022 •CodeCatch
0 likes • 2 views
def byte_size(s): return len(s.encode('utf-8')) byte_size('😀') # 4 byte_size('Hello World') # 11
0 likes • 1 view
#Loop back to this point once code finishes loop = 1 while (loop < 10): #All the questions that the program asks the user noun = input("Choose a noun: ") p_noun = input("Choose a plural noun: ") noun2 = input("Choose a noun: ") place = input("Name a place: ") adjective = input("Choose an adjective (Describing word): ") noun3 = input("Choose a noun: ") #Displays the story based on the users input print ("------------------------------------------") print ("Be kind to your",noun,"- footed", p_noun) print ("For a duck may be somebody's", noun2,",") print ("Be kind to your",p_noun,"in",place) print ("Where the weather is always",adjective,".") print () print ("You may think that is this the",noun3,",") print ("Well it is.") print ("------------------------------------------") #Loop back to "loop = 1" loop = loop + 1
• Mar 10, 2021 •Skrome
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]))
• Jun 1, 2023 •CodeCatch
0 likes • 4 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.")
• Nov 18, 2022 •AustinLeath
0 likes • 3 views
import random class Node: def __init__(self, c): self.left = None self.right = None self.color = c def SetColor(self,c) : self.color = c def PrintNode(self) : print(self.color) def insert(s, root, i, n): if i < n: temp = Node(s[i]) root = temp root.left = insert(s, root.left,2 * i + 1, n) root.right = insert(s, root.right,2 * i + 2, n) return root def MakeTree(s) : list = insert(s,None,0,len(s)) return list def MakeSet() : s = [] count = random.randint(7,12) for _ in range(count) : color = random.randint(0,1) == 0 and "Red" or "White" s.append(color) return s def ChangeColor(root) : if (root != None) : if (root.color == "White") : root.SetColor("Red") ChangeColor(root.left) ChangeColor(root.right) def PrintList(root) : if root.left != None : PrintList(root.left) else : root.PrintNode() if root.right != None : PrintList(root.right) else : root.PrintNode() t1 = MakeTree(MakeSet()) print("Original Colors For Tree 1:\n") PrintList(t1) ChangeColor(t1) print("New Colors For Tree 1:\n") PrintList(t1) t2 = MakeTree(MakeSet()) print("Original Colors For Tree 2:\n") PrintList(t2) ChangeColor(t2) print("New Colors For Tree 2:\n") PrintList(t2) t3 = MakeTree(MakeSet()) print("Original Colors For Tree 3:\n") PrintList(t3) ChangeColor(t3) print("New Colors For Tree 3:\n") PrintList(t3)
# Python program for implementation of Bubble Sort def bubbleSort(arr): n = len(arr) # Traverse through all array elements for i in range(n-1): # range(n) also work but outer loop will repeat one time more than needed. # Last i elements are already in place for j in range(0, n-i-1): # traverse the array from 0 to n-i-1 # Swap if the element found is greater # than the next element if arr[j] > arr[j+1] : arr[j], arr[j+1] = arr[j+1], arr[j] # Driver code to test above arr = [64, 34, 25, 12, 22, 11, 90] bubbleSort(arr) print ("Sorted array is:") for i in range(len(arr)): print ("%d" %arr[i]),