Loading...
More Python Posts
# question3.pyfrom itertools import productV='∀'E='∃'def tt(f,n) :xss=product((0,1),repeat=n)print('function:',f.__name__)for xs in xss : print(*xs,':',int(f(*xs)))print('')# this is the logic for part A (p\/q\/r) /\ (p\/q\/~r) /\ (p\/~q\/r) /\ (p\/~q\/~r) /\ (~p\/q\/r) /\ (~p\/q\/~r) /\ (~p\/~q\/r) /\ (~p\/~q\/~r)def parta(p,q,r) :a=(p or q or r) and (p or q or not r) and (p or not q or r)and (p or not q or not r)b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)c= a and breturn cdef partb(p,q,r) :a=(p or q and r) and (p or not q or not r) and (p or not q or not r)and (p or q or not r)b=(not p or q or r ) and (not p or q or not r) and (not p or not q or r) and (not p or not q or not r)c= a and breturn cprint("part A:")tt(parta,3)print("part B:")tt(partb,3)
import osimport sysimport argparseimport jsonimport csvimport getpassimport stringimport randomimport refrom datetime import datetimeimport ldapimport requestsfrom requests.packages.urllib3.exceptions import InsecureRequestWarningrequests.packages.urllib3.disable_warnings(InsecureRequestWarning)from requests.auth import HTTPBasicAuthimport validatorsdef create_guac_connection(BASE_URL, auth_token, ldap_group, computer, guac_group_id):'''creates a guac connection'''json_header = {'Accept': 'application/json'}query_parm_payload = { 'token': auth_token }payload_data = {"parentIdentifier":guac_group_id,"name":computer,"protocol":"vnc","parameters":{"port":"5900","read-only":"","swap-red-blue":"","cursor":"","color-depth":"","clipboard-encoding":"","disable-copy":"","disable-paste":"","dest-port":"","recording-exclude-output":"","recording-exclude-mouse":"","recording-include-keys":"","create-recording-path":"","enable-sftp":"true","sftp-port":"","sftp-server-alive-interval":"","enable-audio":"","audio-servername":"","sftp-directory":"","sftp-root-directory":"","sftp-passphrase":"","sftp-private-key":"","sftp-username":"","sftp-password":"","sftp-host-key":"","sftp-hostname":"","recording-name":"","recording-path":"","dest-host":"","password":"asdasd","username":"asdasd","hostname":"nt72310.cvad.unt.edu"},"attributes":{"max-connections":"","max-connections-per-user":"1","weight":"","failover-only":"","guacd-port":"","guacd-encryption":"","guacd-hostname":""}}CREATE_CONNECTION_URL = BASE_URL + "/api/session/data/mysql/connections"create_connection_request = requests.post(CREATE_CONNECTION_URL, headers=json_header, params=query_parm_payload, data=payload_data, verify=False)create_connection_result = create_connection_request.status_codeif create_connection_result == "200":print("Successfully created computer: " + computer)else:print(create_connection_request.json())return create_connection_result
# Python program for Plotting Fibonacci# spiral fractal using Turtleimport turtleimport mathdef fiboPlot(n):a = 0b = 1square_a = asquare_b = b# Setting the colour of the plotting pen to bluex.pencolor("blue")# Drawing the first squarex.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 Seriestemp = square_bsquare_b = square_b + square_asquare_a = temp# Drawing the rest of the squaresfor 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 Seriestemp = square_bsquare_b = square_b + square_asquare_a = temp# Bringing the pen to starting point of the spiral plotx.penup()x.setposition(factor, 0)x.seth(0)x.pendown()# Setting the colour of the plotting pen to redx.pencolor("red")# Fibonacci Spiral Plotx.left(90)for i in range(n):print(b)fdwd = math.pi * b * factor / 2fdwd /= 90for j in range(90):x.forward(fdwd)x.left(1)temp = aa = bb = 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 runn = int(input('Enter the number of iterations (must be > 1): '))# Plotting the Fibonacci Spiral Fractal# and printing the corresponding Fibonacci Numberif 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")
# Python program for implementation of Bogo Sortimport random# Sorts array a[0..n-1] using Bogo sortdef bogoSort(a):n = len(a)while (is_sorted(a)== False):shuffle(a)# To check if array is sorted or notdef is_sorted(a):n = len(a)for i in range(0, n-1):if (a[i] > a[i+1] ):return Falsereturn True# To generate permuatation of the arraydef shuffle(a):n = len(a)for i in range (0,n):r = random.randint(0,n-1)a[i], a[r] = a[r], a[i]# Driver code to test abovea = [3, 2, 4, 1, 0, 5]bogoSort(a)print("Sorted array :")for i in range(len(a)):print ("%d" %a[i]),
# Python Program to calculate the square rootnum = float(input('Enter a number: '))num_sqrt = num ** 0.5print('The square root of %0.3f is %0.3f'%(num ,num_sqrt))
def generate_floyds_triangle(num_rows):triangle = []number = 1for row in range(num_rows):current_row = []for _ in range(row + 1):current_row.append(number)number += 1triangle.append(current_row)return triangledef display_floyds_triangle(triangle):for row in triangle:for number in row:print(number, end=" ")print()# Prompt the user for the number of rowsnum_rows = int(input("Enter the number of rows for Floyd's Triangle: "))# Generate Floyd's Trianglefloyds_triangle = generate_floyds_triangle(num_rows)# Display Floyd's Triangledisplay_floyds_triangle(floyds_triangle)