• 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()
• 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])
• Oct 7, 2022 •KETRICK
0 likes • 1 view
import pandas as pd x = pd.read_excel(FILE_NAME) print(x)
• May 31, 2023 •CodeCatch
0 likes • 0 views
import calendar # Prompt user for year and month year = int(input("Enter the year: ")) month = int(input("Enter the month: ")) # Create a calendar object cal = calendar.monthcalendar(year, month) # Display the calendar print(calendar.month_name[month], year) print("Mon Tue Wed Thu Fri Sat Sun") for week in cal: for day in week: if day == 0: print(" ", end="") else: print(str(day).rjust(2), " ", end="") print()
• Nov 18, 2022 •AustinLeath
0 likes • 8 views
#question1.py def rose(n) : if n==0 : yield [] else : for k in range(0,n) : for l in rose(k) : for r in rose(n-1-k) : yield [l]+[r]+[r] def start(n) : for x in rose(n) : print(x) #basically I am printing x for each rose(n) file print("starting program: \n") start(2) # here is where I call the start function
• Nov 19, 2022 •CodeCatch
# Python code to demonstrate # method to remove i'th character # Naive Method # Initializing String test_str = "CodeCatch" # Printing original string print ("The original string is : " + test_str) # Removing char at pos 3 # using loop new_str = "" for i in range(len(test_str)): if i != 2: new_str = new_str + test_str[i] # Printing string after removal print ("The string after removal of i'th character : " + new_str)