Calculate Square Root
0 likes • Nov 18, 2022 • 0 views
Python
Loading...
More Python Posts
import mathdef factorial(n):print(math.factorial(n))return (math.factorial(n))factorial(5)factorial(10)factorial(15)
# Python program for implementation of Bubble Sortdef bubbleSort(arr):n = len(arr)# Traverse through all array elementsfor i in range(n-1):# range(n) also work but outer loop will repeat one time more than needed.# Last i elements are already in placefor j in range(0, n-i-1):# traverse the array from 0 to n-i-1# Swap if the element found is greater# than the next elementif arr[j] > arr[j+1] :arr[j], arr[j+1] = arr[j+1], arr[j]# Driver code to test abovearr = [64, 34, 25, 12, 22, 11, 90]bubbleSort(arr)print ("Sorted array is:")for i in range(len(arr)):print ("%d" %arr[i]),
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 validatorsimport ipdb# ldap functionsdef get_ldap_group_members(ldap_group, user, passwrd, DOMAIN, DOMAIN_SEARCH_BASE):#DOMAIN_GROUP, DOMAIN_USER, DOMAIN_PASS, DOMAIN, DOMAIN_SEARCH_BASE'''Input a user name and search the directory'''#---- Setting up the Connection#account used for binding - Avoid putting these in version controlbindDN = str(user)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://'+str(DOMAIN))conn.protocol_version = 3conn.set_option(ldap.OPT_REFERRALS, 0)#authenticate the connection so that you can make additional queriestry:result = conn.simple_bind_s(bindDN, bindPass)except ldap.INVALID_CREDENTIALS:result = "Invalid credentials for %s" % usersys.exit()#build query in the form of (uid=user)ldap_query = '(cn=' + ldap_group + ')'query_result = []lencount = Truerange_start = 0total_active_students_count = 0while lencount:#print(len(query_result))range_end = range_start + 1499member_range = ['member;range=' + str(range_start) + '-' + str(range_end)]#print(member_range)ldap_info = conn.search_s(str(DOMAIN_SEARCH_BASE), ldap.SCOPE_SUBTREE, filterstr=ldap_query, attrlist=member_range)member_range = next(iter(ldap_info[0][1].keys()))ldap_objects = ldap_info[0][1][member_range]print("\n")for ldap_object in ldap_objects:decoded_member_string = ldap_object.decode("utf-8")member_cn = re.split('=|,', decoded_member_string)[1]print(f"User number: {total_active_students_count} in {ldap_group}: {member_cn}")query_result.append(member_cn)total_active_students_count = total_active_students_count + 1if len(ldap_objects) == 1500:lencount = Truerange_start += 1500range_end += 1500else:lencount = Falseprint(f"TOTAL USERS IN ActiveStudents: {total_active_students_count}")return query_resultdef main():user = input("Enter a UNT bind username: ") + "@students.ad.unt.edu"passwrd = getpass.getpass(prompt='Enter UNT bind password: ', stream=None)get_ldap_group_members("ActiveStudents", user, passwrd, "students.ad.unt.edu", "DC=students,DC=ad,DC=unt,DC=edu")if __name__ == "__main__":main()
primes=[]products=[]def prime(num):if num > 1:for i in range(2,num):if (num % i) == 0:return Falseelse:primes.append(num)return Truefor n in range(30,1000):if len(primes) >= 20:break;else:prime(n)for previous, current in zip(primes[::2], primes[1::2]):products.append(previous * current)print (products)
import subprocess #for the praat callsimport os #for ffmpeg and the pause call at the end#Even if we wanted all videos being rendered asynchronously, we couldn't see progress or errorsimport glob #for the ambiguous filesimport tempfileaudioFileDirectory = 'Audio Files'timeList = {}fileList = glob.glob(audioFileDirectory + '\\*.wav')pipeList = {}for fileName in fileList:arglist = ['Praat.exe', '--run', 'crosscorrelateMatch.praat', 'zeussound.wav', fileName, "0" , "300"]print(' '.join(arglist))pipe = subprocess.Popen(arglist, stdout=subprocess.PIPE)pipeList[fileName[len(audioFileDirectory)+1:-4]] = pipe #+1 because of back slash, -4 because .wav#for fileName, pipe in pipeList.items():# text = pipe.communicate()[0].decode('utf-8')# timeList[fileName] = float(text[::2])for fileName, pipe in pipeList.items():if float(pipe.communicate()[0].decode('utf-8')[::2]) > .0003: #.000166 is not a match, and .00073 is a perfect match. .00053 is a tested matcharglist = ['Praat.exe', '--run', 'crosscorrelate.praat', 'zeussound.wav', audioFileDirectory + '\\' + fileName + '.wav', "0" , "300"]print(' '.join(arglist))text = subprocess.Popen(arglist, stdout=subprocess.PIPE).communicate()[0].decode('utf-8')timeList[fileName] = float(text[::2])clipLength = 10for fileName, time in timeList.items():arglist = ['ffmpeg', '-i', '"'+fileName+'.mp4"', '-ss', str(time-clipLength), '-t', str(clipLength*2), '-acodec', 'copy' , '-vcodec', 'copy', '"ZEUS'+ fileName + '.mp4"']print(' '.join(arglist))os.system(' '.join(arglist))tempFile = tempfile.NamedTemporaryFile(delete=False)for fileName in glob.glob('ZEUS*.mp4'):tempFile.write(("file '" + os.path.realpath(fileName) + "'\n").encode());tempFile.seek(0)print(tempFile.read())tempFile.close()arglist = ['ffmpeg', '-safe', '0', '-f', 'concat', '-i', '"'+tempFile.name+'"', '-c', 'copy', 'ZeusMontage.mp4']print(' '.join(arglist))os.system(' '.join(arglist))os.unlink(tempFile.name) #Delete the temp file#print(timeList)os.system('PAUSE')
from colorama import init, Fore# Initialize coloramainit()print(Fore.RED + "This text is in red color.")print(Fore.GREEN + "This text is in green color.")print(Fore.BLUE + "This text is in blue color.")# Reset coloramaprint(Fore.RESET + "This text is back to the default color.")