• Sep 3, 2025 •AustinLeath
0 likes • 5 views
import subprocess class CommandRunner: def run_command(self, command): command_process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, text=True) output = command_process.communicate()[0].strip() return_code = command_process.returncode return output, return_code def main(): # Create instance of CommandRunner runner = CommandRunner() # Define the command command = 'ping -c 4 localhost' try: # Run the command and get output and return code output, return_code = runner.run_command(command) # Print the output and return code print(f"Command output:\n{output}") print(f"Return code: {return_code}") except Exception as e: print(f"An error occurred: {e}") if __name__ == "__main__": main()
• 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
• Sep 6, 2020 •C S
0 likes • 2 views
def Fibonacci(n): if n<0: print("Incorrect input") # First Fibonacci number is 0 elif n==1: return 0 # Second Fibonacci number is 1 elif n==2: return 1 else: return Fibonacci(n-1)+Fibonacci(n-2) # Driver Program print(Fibonacci(9))
• Mar 26, 2023 •AustinLeath
0 likes • 0 views
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))
• Nov 19, 2022 •CodeCatch
0 likes • 6 views
def when(predicate, when_true): return lambda x: when_true(x) if predicate(x) else x double_even_numbers = when(lambda x: x % 2 == 0, lambda x : x * 2) print(double_even_numbers(2)) # 4 print(double_even_numbers(1)) # 1
• Nov 18, 2022 •AustinLeath
0 likes • 4 views
import itertools import string import time def guess_password(real): chars = string.ascii_lowercase + string.ascii_uppercase + string.digits + string.punctuation attempts = 0 for password_length in range(1, 9): for guess in itertools.product(chars, repeat=password_length): startTime = time.time() attempts += 1 guess = ''.join(guess) if guess == real: return 'password is {}. found in {} guesses.'.format(guess, attempts) loopTime = (time.time() - startTime); print(guess, attempts, loopTime) print("\nIt will take A REALLY LONG TIME to crack a long password. Try this out with a 3 or 4 letter password and see how this program works.\n") val = input("Enter a password you want to crack that is 9 characters or below: ") print(guess_password(val.lower()))