• Nov 18, 2022 •AustinLeath
0 likes • 9 views
#Python 3: Fibonacci series up to n def fib(n): a, b = 0, 1 while a < n: print(a, end=' ') a, b = b, a+b print() fib(1000)
• Aug 1, 2025 •AustinLeath
0 likes • 2 views
import re _proposal_regex = r'(?:(?:(IKE|ESP):)?[\w/]+(?:/NO_EXT_SEQ)?(?:, ?(IKE|ESP):[\w/]+(?:/NO_EXT_SEQ)?)*)?' _proposals_re = rf'(?P<proposals>{_proposal_regex}|)' pattern = rf'received proposals: {_proposals_re}' match = re.match(pattern, 'received proposals: ') print(match.group('proposals') if match else "No match") # Prints "No match"
• Nov 19, 2022 •CodeCatch
import mysql.connector mydb = mysql.connector.connect( host="localhost", user="yourusername", password="yourpassword" ) mycursor = mydb.cursor() mycursor.execute("CREATE DATABASE mydatabase")
0 likes • 1 view
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)
• 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
• 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()