• Nov 19, 2022 •CodeCatch
0 likes • 0 views
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)
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)
• May 31, 2023 •CodeCatch
# Prompt user for a decimal number decimal = int(input("Enter a decimal number: ")) # Convert decimal to binary binary = bin(decimal) # Convert decimal to hexadecimal hexadecimal = hex(decimal) # Display the results print("Binary:", binary) print("Hexadecimal:", hexadecimal)
def key_of_min(d): return min(d, key = d.get) key_of_min({'a':4, 'b':0, 'c':13}) # b
• Mar 26, 2023 •AustinLeath
import os # Get the current directory current_dir = os.getcwd() # Loop through each file in the current directory for filename in os.listdir(current_dir): # Check if the file name starts with a number followed by a period and a space if filename[0].isdigit() and filename[1] == '.' and filename[2] == ' ': # Remove the number, period, and space from the file name new_filename = filename[3:] # Rename the file os.rename(os.path.join(current_dir, filename), os.path.join(current_dir, new_filename))
1 like • 3 views
def hex_to_rgb(hex): return tuple(int(hex[i:i+2], 16) for i in (0, 2, 4)) hex_to_rgb('FFA501') # (255, 165, 1)