• Jul 24, 2024 •AustinLeath
0 likes • 3 views
from statistics import median, mean, mode def print_stats(array): print(array) print("median =", median(array)) print("mean =", mean(array)) print("mode =", mode(array)) print() print_stats([1, 2, 3, 3, 4]) print_stats([1, 2, 3, 3])
• Jul 2, 2025 •AustinLeath
0 likes • 1 view
import calendar from datetime import datetime # Get the UTC timestamp a = calendar.timegm(datetime.utcnow().utctimetuple()) print(a)
• Oct 10, 2025 •AustinLeath
0 likes • 2 views
#Original def output_json_log_data_to_file(filename, record_dictionary_list): with open(filename, 'w') as outputFile: for record in record_dictionary_list: json.dump(record, outputFile) outputFile.write('\n') #Atomic def output_json_log_data_to_file(filename, record_dictionary_list): # Use atomic file operations to prevent race conditions with readers # Write to temporary file first, then atomically rename to target file tmp_filename = filename + '.tmp' with open(tmp_filename, 'w') as outputFile: for record in record_dictionary_list: json.dump(record, outputFile) outputFile.write('\n') # Atomic rename - this prevents readers from seeing partial writes shutil.move(tmp_filename, filename)
• 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
• Nov 19, 2022 •CodeCatch
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)
• Jun 1, 2023 •CodeCatch
0 likes • 4 views
bytes_data = b'Hello, World!' string_data = bytes_data.decode('utf-8') print("String:", string_data)