• 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)
• Sep 20, 2025 •cntt.dsc-f4b6
1 like • 2 views
print(123)
• May 31, 2023 •CodeCatch
0 likes • 1 view
def generate_pascals_triangle(num_rows): triangle = [] for row in range(num_rows): # Initialize the row with 1 current_row = [1] # Calculate the values for the current row if row > 0: previous_row = triangle[row - 1] for i in range(len(previous_row) - 1): current_row.append(previous_row[i] + previous_row[i + 1]) # Append 1 at the end of the row current_row.append(1) # Add the current row to the triangle triangle.append(current_row) return triangle def display_pascals_triangle(triangle): for row in triangle: for number in row: print(number, end=" ") print() # Prompt the user for the number of rows num_rows = int(input("Enter the number of rows for Pascal's Triangle: ")) # Generate Pascal's Triangle pascals_triangle = generate_pascals_triangle(num_rows) # Display Pascal's Triangle display_pascals_triangle(pascals_triangle)
• Jun 1, 2023 •CodeCatch
0 likes • 2 views
filename = "data.txt" with open(filename, "r") as file: file_contents = file.readlines() file_contents = [line.strip() for line in file_contents] print("File contents:") for line in file_contents: print(line)
0 likes • 0 views
def get_ldap_user(member_cn, user, passwrd): ''' Get an LDAP user and return the SAMAccountName ''' #---- Setting up the Connection #account used for binding - Avoid putting these in version control bindDN = str(user) + "@unt.ad.unt.edu" bindPass = passwrd #set some tuneables for the LDAP library. ldap.set_option(ldap.OPT_X_TLS_REQUIRE_CERT, ldap.OPT_X_TLS_ALLOW) #ldap.set_option(ldap.OPT_X_TLS_CACERTFILE, CACERTFILE) conn = ldap.initialize('ldaps://unt.ad.unt.edu') conn.protocol_version = 3 conn.set_option(ldap.OPT_REFERRALS, 0) #authenticate the connection so that you can make additional queries try: result = conn.simple_bind_s(bindDN, bindPass) except ldap.INVALID_CREDENTIALS: result = "Invalid credentials for %s" % user sys.exit() #build query in the form of (uid=user) ldap_query = '(|(displayName=' + member_cn + ')(cn='+ member_cn + ')(name=' + member_cn + '))' ldap_info = conn.search_s('DC=unt,DC=ad,DC=unt,DC=edu', ldap.SCOPE_SUBTREE, filterstr=ldap_query) sAMAccountName = str(ldap_info[0][1]['sAMAccountName']).replace("[b'", "").replace("']","") return sAMAccountName
• Nov 19, 2022 •CodeCatch
# Python program for Plotting Fibonacci # spiral fractal using Turtle import turtle import math def fiboPlot(n): a = 0 b = 1 square_a = a square_b = b # Setting the colour of the plotting pen to blue x.pencolor("blue") # Drawing the first square x.forward(b * factor) x.left(90) x.forward(b * factor) x.left(90) x.forward(b * factor) x.left(90) x.forward(b * factor) # Proceeding in the Fibonacci Series temp = square_b square_b = square_b + square_a square_a = temp # Drawing the rest of the squares for i in range(1, n): x.backward(square_a * factor) x.right(90) x.forward(square_b * factor) x.left(90) x.forward(square_b * factor) x.left(90) x.forward(square_b * factor) # Proceeding in the Fibonacci Series temp = square_b square_b = square_b + square_a square_a = temp # Bringing the pen to starting point of the spiral plot x.penup() x.setposition(factor, 0) x.seth(0) x.pendown() # Setting the colour of the plotting pen to red x.pencolor("red") # Fibonacci Spiral Plot x.left(90) for i in range(n): print(b) fdwd = math.pi * b * factor / 2 fdwd /= 90 for j in range(90): x.forward(fdwd) x.left(1) temp = a a = b b = temp + b # Here 'factor' signifies the multiplicative # factor which expands or shrinks the scale # of the plot by a certain factor. factor = 1 # Taking Input for the number of # Iterations our Algorithm will run n = int(input('Enter the number of iterations (must be > 1): ')) # Plotting the Fibonacci Spiral Fractal # and printing the corresponding Fibonacci Number if n > 0: print("Fibonacci series for", n, "elements :") x = turtle.Turtle() x.speed(100) fiboPlot(n) turtle.done() else: print("Number of iterations must be > 0")