def decimal_to_quinary(decimal_number): '''Convert decimal number to quinary number For an instance, lets take decimal_number as 123 then, To calculate decimal_number to quinary you need to: 5 | 123 | 3 >>> Remainder ------ 5 | 24 | 4 >>> Remainder ------ 4 >>> Remainder Required quinary number is 443 ''' try: global quinary_number quinary_number = '' decimal_number = int(decimal_number) # Converting into quinary while decimal_number > 0: quinary_number += str(decimal_number % 5) decimal_number = decimal_number // 5 quinary_number = quinary_number[::-1] return quinary_number except ValueError: MessageBeep() display_answer('Invalid Decimal Number')
def quinary_to_decimal(quinary_number): '''Convert quinary number to decimal number You can convert quinary number to decimal by multiplying each quinary number with base of 5 with power starting from 0 increasing from left to right. For an instance, lets take quinary number be 123 Step 1: Converting to decimal number 123 = 1 * 5^2 + 2 * 5^1 + 3 * 5^0 = 38 And our required quinary number is 38 ''' global decimal_number if is_quinary(quinary_number): decimal_number = 0 reversed_binary = str(quinary_number)[::-1] for index, value in enumerate(reversed_binary): decimal_number += int(value) * 5 ** index return decimal_number else: MessageBeep() display_answer('Invalid Quinary Number')
def register(driver, captcha_num, lecture_name): msg = "" # 빈 강의가 있으면 비프음으로 알린 후 수강 신청. MessageBeep() try: driver.find_element_by_id("inputTextView").send_keys(captcha_num) driver.find_element_by_xpath( "//*[@id='content']/div/div[2]/div[2]/div[2]/a").click() WebDriverWait(driver, WAIT_LIMIT_IN_SECONDS).until(EC.alert_is_present()) alert = driver.switch_to.alert msg = alert.text alert.accept() except TimeoutException: print("알람이 떠야하는데 안 뜸.") finally: # 수강신청 성공하면 그만 돌려도 되니까 드라이버 종료. if "수강신청되었습니다" in msg: print_msg(True, lecture_name, msg) exit_driver(driver) else: # 다른 메시지가 출력되면 신청 실패. 다시 돌아가기. print_msg(False, lecture_name, msg) run(driver)
def decimal_to_octal(decimal_number): '''Convert decimal number to octal number To convert decimal to octal you need to divide decimal number by 0: For an instance, lets take decimal number as 98 8 | 123 | 3 >>> Remainder ----- 8 | 15 | 7 >>> Remainder ----- 1 >>> Remainder And writing the remainder in reverse way i.e 173 ''' try: global octal_number octal_number = '' decimal_number = int(decimal_number) # Converting into octal while decimal_number > 0: octal_number += str(decimal_number % 8) decimal_number = decimal_number // 8 octal_number = octal_number[::-1] return octal_number except ValueError: MessageBeep() display_answer('Invalid Decimal Number')
def binary_to_decimal(binary_number): '''Convert binary number to decimal number To convert binary to decimal you need to: Multipy each number by base 2 with its own power increase from left to right(first power is 0) 1111011 = 1 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 = 123 Required decimal number is 123 ''' global decimal_number decimal_number = 0 if is_binary(binary_number): reversed_binary = str(binary_number)[::-1] # Converting to decimal for bin_num in range(len(binary_number)): decimal_number += int(reversed_binary[bin_num]) * 2 ** bin_num return decimal_number else: MessageBeep() display_answer('Invalid Binary Number')
def download_mp4(self): """ Function for downloading in .mp4 """ self.video.register_on_progress_callback(self.progress_func_mp4) titre_rename = self.character_control(self.titre_yt) path_folder_and_file_name = Path(self.folderpath, titre_rename) path_final = self.unique_filename(path_folder_and_file_name, '.mp4') titre_rename = path_final.name audio_stream = self.video.streams.filter(adaptive=True, only_audio=True, file_extension='mp4').desc() video_stream = self.video.streams.filter( adaptive=True, res='1080p', file_extension='mp4').order_by('resolution').desc() if len(video_stream) == 0: # if no 1080 video_stream = self.video.streams.filter( adaptive=True, file_extension='mp4').order_by('resolution').desc() self.loadbar = ProgressBar( 100, title=f"{self.titre_yt} video download in progress ") video_stream.first().download(self.path_temp, filename='video') self.loadbar = ProgressBar( 100, title=f"{self.titre_yt} audio download in progress ") audio_stream.first().download(self.path_temp, filename='audio') # -----------------------merging-------------------------------------------- filePathVideo = Path(self.path_temp, 'video') filePathAudio = Path(self.path_temp, 'audio') filePathFinal = Path(self.path_temp, 'final.mp4') subprocess.run([ "./FFmpeg/bin/ffmpeg.exe", '-i', filePathAudio, "-i", filePathVideo, '-c', 'copy', filePathFinal ]) os.remove(filePathVideo) os.remove(filePathAudio) # we delete the .mp4 file created in the first place filePathFinal = filePathFinal.rename( filePathFinal.with_name(titre_rename + ".mp4")) # we rename the .mp3 file # we move the file to the good directory shutil.move(filePathFinal, self.folderpath) try: # if window MessageBeep(-1) #beep except: pass
def download_mp3(self): """ Function for downloading into .mp3 """ self.loadbar = ProgressBar( 100, title=f"{self.titre_yt} download in progress ") # create a instance of the class for showing progress # function call when we retrive a chunk of dat self.video.register_on_progress_callback(self.progress_func_mp3) # The name we will use to rename the file, witout bad characters titre_rename = self.character_control(self.titre_yt) titre_enregistrement = 'FFMPEG_compatible' # name compatible with FFMPEG path_folder_and_file_name = Path(self.folderpath, titre_rename) path_final = self.unique_filename(path_folder_and_file_name, '.mp3') titre_rename = path_final.name # we get the final name for the file ; if on a folder they already have the file with the same name we had a number in front yt_str = self.video.streams.filter(only_audio=True, file_extension='mp4').first() yt_str.download(self.path_temp, filename=titre_enregistrement) # We download the video by filtering all of the tracks, and we only keep the audio. # That saves the file in a .mp4 format into the Temp file # -----------------------conversion-------------------------------------------- filePathMp4 = Path(self.path_temp, "FFMPEG_compatible.mp4") filePathMp3 = Path(self.path_temp, "FFMPEG_compatible.mp3") # command for converting .mp4 to .mp3 ffmpeg = subprocess.call( ["./FFmpeg/bin/ffmpeg.exe", '-i', filePathMp4, filePathMp3]) self.loadbar.setValue(99) # the download stop at 98% os.remove(filePathMp4) # we delete the .mp4 file created filePathMp3 = filePathMp3.rename( filePathMp3.with_name(titre_rename + ".mp3")) # we rename the .mp3 file # we move the file to the good directory shutil.move(filePathMp3, self.folderpath) self.loadbar.setValue(100) # we show that the process had finish try: # if window MessageBeep(-1) #beep except: pass
def octal_to_binary(octal_number): ''' For an instance, lets take an octal number 123 To calculate you need to: Step 1: Convert the given octal number to decimal. 123 = 1 * 8^2 + 2 * 8^1 + 3 * 8^0 = 83 Step 2: Convert the obtained decimal to binary 2 | 83 | 1 <<< Remainder ------- 2 | 41 | 1 <<< Remainder ------- 2 | 20 | 0 <<< Remainder ------- 2 | 10 | 0 <<< Remainder ------- 2 | 5 | 1 <<< Remainder ------- 2 | 2 | 0 <<< Remainder ------- 1 And our required binary is 1010011 ''' global binary_number if is_octal(octal_number): binary_number = '' decimal_number = octal_to_decimal(octal_number) # Converting into obtained decimal to binary while decimal_number > 0: binary_number += str(decimal_number % 2) decimal_number = decimal_number // 2 binary_number = binary_number[::-1] else: MessageBeep() display_answer('Invalid Octal Number')
def is_octal(octal_number): '''Check if the given number is octal''' try: count = 0 for oct_num in str(octal_number): if not oct_num.isdigit() or int(oct_num) > 7: count += 1 if count == 0: return True else: return False except ValueError: MessageBeep() display_answer('Invalid Octal Number')
def is_quinary(quinary_number): '''Check if the given number is quinary''' try: count = 0 for quinary in str(quinary_number): if int(quinary) >= 5: count += 1 if count == 0: return True else: return False except ValueError: MessageBeep() display_answer('Invalid Quinary Number')
def binary_to_quinary(binary_number): '''Convert binary number to quinary number To convert quinary to binary we need to: Step 1: Convert given binary to decimal For instance, lets take binary_number as 1111011 then, Converting 1111011 to decimal, we get: 1111011 = 1 * 2^6 + 1 * 2^5 + 1 * 2^4 + 1 * 2^3 + 0 * 2^2 + 1 * 2^1 + 1 * 2^0 = 123 (decimal number) Step 2: Convert the obtained decimal number to quinary number = 5 | 123 | 3 >>> Remainder ------ 5 | 24 | 4 >>> Remainder ------ 4 Required quinary number is 443 taken in reverse ways ''' global quinary_number if is_binary(binary_number): quinary_number = '' decimal_number = 0 reversed_binary = str(binary_number)[::-1] # Converting binary to decimal decimal_number = binary_to_decimal(reversed_binary) # Converting obtained decimal to quinary while decimal_number > 0: quinary_number += str(decimal_number % 5) decimal_number = decimal_number // 5 quinary_number = quinary_number[::-1] else: MessageBeep() display_answer('Inalid quinary number')
def is_binary(binary_number): '''Check if the given number is binary''' try: count = 0 for binn in str(binary_number): if not binn.isdigit() or int(binn) > 1: count += 1 if count == 0: return True else: return False except ValueError: MessageBeep() display_answer('Invalid Binary Number')
def octal_to_hexadecimal(octal_number): '''Convert octal number to hexadecimal number To convert octal number to hexadecimal you need to first convert the octal number to decimal and obtained decimal to hexadecimal For an instance, lets take an octal number 123 Step 1: Convert octal number(123) to decimal 123 = 1 * 8^2 + 2 * 8^1 + 3 * 8^0 = 83 (decimal number) Step 2: Then, convert obtained decimal number to octal 16 | 83 | 3 >>> Remainder ------ 5 >>> Remainder And our required hexadecimal is 53 (taking remainder in reverse(i.e from down to up)) ''' global hexadecimal if is_octal(octal_number): decimal_number = 0 hexadecimal = '' decimal_number = octal_to_decimal(octal_number) # Converting to hexadecimal while decimal_number > 0: get_remainder = str(decimal_number % 16) if int(get_remainder) > 9: hexadecimal += num_to_hex[get_remainder] else: hexadecimal += get_remainder decimal_number = decimal_number // 16 hexadecimal = hexadecimal[::-1] else: MessageBeep() display_answer('Invalid Octal Number')
def quinary_to_binary(quinary_number): '''Convert quinary number to binary number You can convert quinary number to binary, first by converting quinary number to decimal and obtained decimal to binary number For an instance, lets take quinary number be 123 Step 1: Convert quinary number to decimal 123 = 1 * 5^2 + 2 * 5^1 + 3 * 5^0 = 38 (Decimal) Step 2: Convert obtained decimal number to binary 2 | 38 | 0 ----- 2 | 19 | 1 ----- 2 | 9 | 1 ----- 2 | 4 | 0 ----- 2 | 2 | 0 ----- 1 And our required binary number is 100110 (taken remainder in reverse way) ''' global binary_number if is_quinary(quinary_number): decimal_number = 0 reversed_quinary = str(quinary_number)[::-1] for index, value in enumerate(reversed_quinary): decimal_number += int(value) * 5 ** index binary_number = decimal_to_binary(decimal_number) else: MessageBeep() display_answer('Invalid Quinary Number')
def decimal_to_binary(decimal_number): '''Convert decimal number to binary number To convert decimal to binary you need to divide the decimal number by 2 and write the remainder in reverse way For an instance, lets take decimal number as 33, then the calculation is as follow: 2 | 123 | 1 >>> Remainder ------ 2 | 61 | 1 >>> Remainder ------ 2 | 30 | 0 >>> Remainder ----- 2 | 15 | 1 >>> Remainder ----- 2 | 7 | 1 >>> Remainder ------ 2 | 3 | 1 >>> Remainder ------ 1 Required binary number is 1111011 (writing in reverse) ''' global binary_number try: binary_number = '' decimal_number = int(decimal_number) # Converting into binary number while decimal_number > 0: binary_number += str(decimal_number % 2) decimal_number = decimal_number // 2 binary_number = binary_number[::-1] return binary_number except ValueError: MessageBeep() display_answer('Invalid Decimal Number')
def octal_to_quinary(octal_number): '''Convert octal number to quinary number You can covert octal_number to binary by converting the given octal_number to decimal and then obtained decimal to quinary For an instance, lets take an octal number to be 123 Step 1: Covert octal number to decimal number 123 = 1 * 8^2 + 2 * 8^1 + 3 * 8^0 = 83 (decimal number) Step 2: Convert the obtained decimal number to quinary number 5 | 83 | 3 ----- 5 | 16 | 1 ----- 3 REQUIRED QUINARY NUMBER is 313 (taking remainder in reverse order) ''' global quinary_number quinary_number = '' if is_octal(octal_number): # Converting to decimal decimal_number = octal_to_decimal(octal_number) # Converting obtained decimal to quinary while decimal_number > 0: quinary_number += str(decimal_number % 5) decimal_number = decimal_number // 5 quinary_number = quinary_number[::-1] else: MessageBeep() display_answer('Invalid Octal Number')
def hexadecimal_to_decimal(hexadecimal_number): '''Convert hexadecimal number to decimal number To convert hexadecimal to decimal you need to: Multipy each number by base 16 with its own power increase from left to right(first power is 0) 123 = 1 * 16^2 + 2 * 16^1 + 3 * 16^0 = 291 ''' global decimal_number decimal_number = 0 if is_hexadecimal(hexadecimal_number): if hexadecimal_number.isalpha() or not hexadecimal_number.isdigit(): split_hexadecimal = list(str(hexadecimal_number)) for index, split_hexa_decimal in enumerate(split_hexadecimal): if split_hexa_decimal.upper() in hex_to_num: split_hexadecimal[index] = hex_to_num[split_hexa_decimal.upper()] reverse_split_hexadecimal = split_hexadecimal[::-1] for index, value in enumerate(reverse_split_hexadecimal): decimal_number += int(value) * 16 ** index else: reversed_hexadecimal = hexadecimal_number[::-1] # Converting to decimal for index, value in enumerate(reversed_hexadecimal): decimal_number += int(value) * 16 ** index return decimal_number else: MessageBeep() display_answer('Invalid Hexadecimal Number')
def decimal_to_hexadecimal(decimal_number): '''Convert decimal number to hexadecimal number To convert decimal number to hexadecimal, you need to: For instance, lets take decimal number as 123 Divide decimal number until remainder becomes 0 16| 123 | 11 (B) >>> Remainder ------ 7 >>> Remainder Required hexadecimal number is 7B ''' try: global hexadecimal_number hexadecimal_number = '' decimal_number = int(decimal_number) # Converting intto hexadecimal number while decimal_number > 0: get_remainder = decimal_number % 16 if get_remainder > 9: hexadecimal_number += num_to_hex[str(get_remainder)] else: hexadecimal_number += str(get_remainder) decimal_number = decimal_number // 16 hexadecimal_number = hexadecimal_number[::-1] return hexadecimal_number except ValueError: MessageBeep() display_answer('Invalid Decimal Number')
def octal_to_decimal(octal_number): '''Convert octal number to decimal number To convert octal to decimal you need to: Multipy each number by base 8 with its own power increase from left to right(first power is 0) 123 = 1 * 8^2 + 2 * 8^1 + 3 * 8^0 = 83 ''' global decimal_number if is_octal(octal_number): decimal_number = 0 reversed_octal = str(octal_number)[::-1] for x in range(len(reversed_octal)): decimal_number += int(reversed_octal[x]) * 8 ** x return decimal_number else: MessageBeep() display_answer('Invalid Octal Number')
def toasts(): idtxt = open("youxue_user_id.txt", 'r') user_id = idtxt.read() sumNum = 0 while True: sumNum += 1 messages = getMessage(user_id) for message in messages: if "发布了新作业" in message['content']: MessageBeep() # msgbox(message['content'], title= message['title'],ok_button="知道啦") if ccbox(message['content'], title=message['title'], choices=("知道啦", "马上去做")): delMessage(user_id, [message['message_id']]) else: from webbrowser import open as opurl opurl("https://e.anoah.com/ebags/") delMessage(user_id, [message['message_id']]) curr_time = datetime.datetime.now() time_str = datetime.datetime.strftime(curr_time, '%Y-%m-%d %H:%M:%S') print("第%i次刷新,时间:%s,消息%i条" % (sumNum, time_str, len(messages))) del messages, curr_time, time_str sleep(180)
def binary_to_octal(binary_number): '''Convert binary number to octal number Binary number = 1111011 To convert it to octal number: Step 1: Split each three value from backward like 1 111 011 Step 2: Here, we have all splited value having length 3 except one i.e 1 so adding extra two '0's in the front of 1 001 to make its length 3 Then finally we have, 001 111 011 Step 3: Now using 4,2,1 rule so, first, 001 = 0 * 4 + 0 * 2 + 1 * 1 = 1 second, 111 = 1 * 4 + 1 * 2 + 1 * 1 = 7 third, 011 = 0 * 4 + 1 * 2 + 1 * 1 = 3 Step 4: Append each value from first, second, and third which becomes to 173 Required octal number is 173 ''' global octal_number if is_binary(binary_number): binary_number = str(binary_number)[::-1] test_octal = 0 rule = [4, 2, 1] listed_value = [] octal_number = '' for i in range(len(binary_number) // 3 + 1): ''' Here, len(binary_number) = 8 Then, len(binary_number) // 3 + 1 = 2 + 1 = 3 So, xrange = (0, 1, 2) ''' sliced_binary = binary_number[:3] # Storing three value from binary_number in each itreation binary_number = binary_number[3:] # Overwriting binary_number variable excluding value stored in sliced_binary using slicing if len(sliced_binary) == 3: # Checking if the length of value stored in sliced_binary variable listed_value.append(sliced_binary[::-1]) # Then, appending listed_value list by reversing value stored in sliced_binary else: listed_value.append(sliced_binary[::-1].zfill(3)) '''If length of sliced_binary is less than 3 then: First, reversing value of sliced_binary Second, filling 0 to make three character value For instance, At last we get, 01 whose length is less than 3 then we reverse it so we get 10 and we fill that value '10' with '0' using zfill(3) '010' so that the length becomes 3 ''' listed_value = listed_value[::-1] # Reversing the value of listed_value "list" for l in listed_value: # looping to each value in listed_value list for x in range(len(l)): # Then we get range value (0,1,2) which is stored in temporary variable 'x' in each iteration. Here, xrange is generator (python 2.7) test_octal += int(l[x]) * rule[x] # Here, first slicing value from 'l' and rule with the value 'x' and converting value got from l by slicing into integer octal_number += str(test_octal) # Converting integer value stored in test_octal to string and appending it to octal_number variable test_octal = 0 # Overwriting test_octal variable to '0' again octal_number = octal_number.lstrip('0') else: MessageBeep() display_answer('Invalid binary number')
def fit(self, inputData, nEpochs, seqLen, eta, recLossEvery=50, printLossEvery=5000, printQuoteEvery=5000, incr=None, overlap=False, resume=False, save=True, verbose=True): """ Fit model to data. inputData = the entire text to be trained on. In this case the entire book. - type : string nEpochs = number of epochs to train the network. One epoch = one complete "readthrough" of inputData. - type : int seqLen = length of each character sequence to be used in minibatch. - type : int eta = learning rate - type : float recLossEvery = record loss every recLossEvery steps. - type : int printLossEvery = if verbose == True, print smoothed loss every printLossEvery steps. - type : int printQuoteEvery = if verbose == True, print a synthesized text sequence every printQuoteEvery steps. - type : int incr = increment. Value deciding how many characters to jump ahead after finishing the previous sequence. If incr < seqLen nearby sequences will overlap. If incr > seqLen some data will be skipped. If incr == seqLen or incr is None data will be read without skip or overlap. Only applies if overlap == True - type int overlap = see incr. - type : boolean resume = allows the network to resume training from where it previously stopped. - type : boolean save = saves: network loss and smoothed loss to an npz file with name (ddmmyyHHMM_loss.npz). network parameters to another npz file (ddmmyyHHMM_pars.npz). - type : boolean verbose = if true, print some stuff, if false, print no stuff. - type : boolean """ self.eta = eta self.data = inputData n = len(self.data) if not (overlap): incr = seqLen if not (resume): self.it = 0 for _ in trange(nEpochs): e = 0 hprev = np.zeros((self.m, 1)) while (e < n - seqLen - 2): X, Y = self.makeOneHot(self.data[e:e + seqLen + 1]) A, H, P = self.forwardProp(X, hprev) hprev = H[:, [-1]] self.computeGradients(X, Y, A, H, P) loss_t = self.computeLoss(P, Y) self.updatePars(eta=eta) if self.it % recLossEvery == 0: self.loss.append(loss_t) if len(self.smoothLoss) == 0: self.smoothLoss.append(loss_t) else: self.smoothLoss.append( np.average([self.smoothLoss[-1], loss_t], weights=[.99, .01])) if self.it % printLossEvery == 0: if verbose: print("Smooth loss at iteration {0} : {1}".format( self.it, self.smoothLoss[-1])) if self.it % printQuoteEvery == 0: txt = self.synthTxt(200, hprev, X[:, [0]]) self.quotes.append(txt) if verbose: print("Synthesized text at iteration {0}:".format( self.it)) print(txt) e += incr self.it += 1 if save: now = datetime.now() filename = "savefiles/" + now.strftime("%d%m%y%H%M%S") np.savez(filename + '_loss', loss=self.loss, smoothLoss=self.smoothLoss) np.savez(filename + '_pars', U=self.pars["U"], V=self.pars["V"], W=self.pars["W"], b=self.pars["b"], c=self.pars["c"]) if verbose: print("Loss and pars saved to {0}".format(filename)) MessageBeep()
def binary_to_hexadecimal(binary_number): '''Convert binary number to hexadecimal number Binary number = 1111011 To convert it to hexadecimal number: Step 1: Split each four value from backward like 111 1011 Step 2: Here, in first part the length is less than 4 so adding extra 0 at its front and 111 becomes 0111 Step 3: Now using 8,4,2,1 rule in each splitted value so, first, 0111 = 0 * 8 + 1 * 4 + 1 * 2 + 1 * 1 = 7 second, 1011 = 1 * 8 + 0 * 4 + 1 * 2 + 1 * 1 = 11 (B) In Hexadecimal, 10 = A 11 = B 12 = C 13 = D 14 = E 15 = F Step 4: Append each value from first, second, and third which becomes to 7B Required hexadecimal number is 7B ''' global hexadecimal_number if is_binary(binary_number): binary_number = str(binary_number)[::-1] hexa_decimal_value = {'10': 'A', '11': 'B', '12': 'C', '13': 'D', '14': 'E', '15': 'F'} get_remainder = 0 rule = [8, 4, 2, 1] listed_value = [] hexadecimal_number = '' for i in range(len(binary_number) // 4 + 1): ''' Here, len(binary_number) = 8 Then, len(binary_number) // 4 + 1 = 2 + 1 = 4 So, xrange = (0, 1, 2, 3) ''' sliced_binary = binary_number[:4] # Storing three value from binary_number in each itreation binary_number = binary_number[4:] # Overwriting binary_number variable excluding value stored in sliced_binary using slicing if len(sliced_binary) == 4: # Checking if the length of value stored in sliced_binary variable listed_value.append(sliced_binary[::-1]) # Then, appending listed_value list by reversing value stored in sliced_binary else: listed_value.append(sliced_binary[::-1].zfill(4)) '''If length of sliced_binary is less than 4 then: First, reversing value of sliced_binary Second, filling 0 to make three character value For instance, At last we get, 01 whose length is less than 4 then we reverse it so we get 10 and we fill that value '10' with '0' using zfill(3) '010' so that the length becomes 4 ''' listed_value = listed_value[::-1] # Reversing the value of listed_value "list" for l in listed_value: # looping to each value in listed_value list for x in range(len(l)): # Then we get range value (0,1,2, 3) which is stored in temporary variable 'x' in each iteration. Here, xrange is generator (python 2.7) get_remainder += int(l[x]) * rule[x] # Here, first slicing value from 'l' and rule with the value 'x' and converting value got from 'l' by slicing into integer if get_remainder > 9: get_remainder = hexa_decimal_value[str(get_remainder)] hexadecimal_number += str(get_remainder) # Converting integer value stored in get_remainder to string and appending it to hexadecimal_number variable get_remainder = 0 # Overwriting get_remainder variable to '0' again hexadecimal_number = hexadecimal_number.lstrip('0') else: MessageBeep() display_answer('Invalid binary number')
soma_total = 0 neurite_total = 0 for i in range(len(tree_lengths)): if tree_classes[i] == 'SomaOutgrowth': soma_total += tree_lengths[i] elif tree_classes[i] == 'NeuriteOutgrowth': neurite_total += tree_lengths[i] with open(root + measurement_filename2, 'a', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL) spamwriter.writerow([strain] + [age] + [name] + [series] + [neurontype] + [str(soma_total)] + [str(tree_classes.count('SomaOutgrowth'))] + [str(neurite_total)] + [str(tree_classes.count('NeuriteOutgrowth'))] + [str(kinks_count)] + [str(soma_volume)] + [str(density_total)] + [str(density_around_outgrowths)] + [str(angle_threshold)] + [gaussian_sigma] + [str(0)]) #spamwriter.writerow([strain] + [age] + [name] + [series] + [neurontype] + ['SomaOutgrowth'] + [str(soma_total)] + [str(tree_classes.count('SomaOutgrowth'))] + [gaussian_sigma] + [str(0)]) #print('***DONE***') MessageBeep()
minuets = int(input("minuets")) seconds = int(input("seconds")) secc = 0 while minuets > 0 or seconds > 0: print(str(minuets) + ":" + str(seconds)) secc += 1 seconds -= 1 sleep(1) if seconds == 0 and minuets > 0: seconds = 59 minuets -= 1 print("time up") print("") MessageBeep(0) sleep(2) MessageBeep(0) sleep(2) MessageBeep(0) sleep(1) MessageBeep(0) sleep(1) MessageBeep(0) sleep(1) MessageBeep(0) sleep(0.5) MessageBeep(0) sleep(0.5) MessageBeep(0) sleep(0.5)
def calculation(event=None): '''Calculate number with respective selected conversion''' if entry.get() == 'Enter Number' or len(entry.get()) == 0: MessageBeep() display_answer('Input Valid Number') elif combo_box.get() == 'Select Number System': MessageBeep() display_answer('Select Valid Conversion') elif len(entry.get()) != 0: get_value = entry.get() if combo_box.get() == 'Binary to Decimal': binary_to_decimal(get_value) if is_binary(get_value) and len(str(decimal_number)) != 0: display_answer(decimal_number) elif combo_box.get() == 'Binary to Octal': binary_to_octal(get_value) if is_binary(get_value) and len(octal_number) != 0: display_answer(octal_number) elif combo_box.get() == 'Binary to Hexadecimal': binary_to_hexadecimal(get_value) if is_binary(get_value) and len(hexadecimal_number) != 0: display_answer(hexadecimal_number) elif combo_box.get() == 'Binary to Quinary': binary_to_quinary(get_value) if is_binary(get_value) and len(quinary_number) != 0: display_answer(quinary_number) elif combo_box.get() == 'Decimal to Binary': decimal_to_binary(get_value) if len(binary_number) != 0: display_answer(binary_number) elif combo_box.get() == 'Decimal to Octal': decimal_to_octal(get_value) if len(octal_number) != 0: display_answer(octal_number) elif combo_box.get() == 'Decimal to Hexadecimal': decimal_to_hexadecimal(get_value) if len(hexadecimal_number) != 0: display_answer(hexadecimal_number) elif combo_box.get() == 'Decimal to Quinary': decimal_to_quinary(get_value) if len(quinary_number) != 0: display_answer(quinary_number) elif combo_box.get() == 'Octal to Binary': octal_to_binary(get_value) if is_octal(get_value) and len(binary_number) != 0: display_answer(binary_number) elif combo_box.get() == 'Octal to Decimal': octal_to_binary(get_value) if is_octal(get_value) and len(str(decimal_number)) != 0: display_answer(decimal_number) elif combo_box.get() == 'Octal to Hexadecimal': octal_to_hexadecimal(get_value) if is_octal(get_value) and len(str(hexadecimal)) != 0: display_answer(hexadecimal) elif combo_box.get() == 'Octal to Quinary': octal_to_quinary(get_value) if is_octal(get_value) and len(str(quinary_number)) != 0: display_answer(quinary_number) elif combo_box.get() == 'Hexadecimal to Binary': hexadecimal_to_binary(get_value) if is_hexadecimal(get_value) and len(str(binary_number)) != 0: display_answer(binary_number) elif combo_box.get() == 'Hexadecimal to Decimal': hexadecimal_to_decimal(get_value) if is_hexadecimal(get_value) and len(str(decimal_number)) != 0: display_answer(decimal_number) elif combo_box.get() == 'Hexadecimal to Octal': hexadecimal_to_octal(get_value) if is_hexadecimal(get_value) and len(str(octal_number)) != 0: display_answer(octal_number) elif combo_box.get() == 'Hexadecimal to Quinary': hexadecimal_to_quinary(get_value) if is_hexadecimal(get_value) and len(str(quinary_number)) != 0: display_answer(quinary_number) elif combo_box.get() == 'Quinary to Binary': quinary_to_binary(get_value) if is_quinary(get_value) and len(str(binary_number)) != 0: display_answer(binary_number) elif combo_box.get() == 'Quinary to Decimal': quinary_to_decimal(get_value) if is_quinary(get_value) and len(str(decimal_number)) != 0: display_answer(decimal_number) elif combo_box.get() == 'Quinary to Octal': quinary_to_octal(get_value) if is_quinary(get_value) and len(str(octal_number)) != 0: display_answer(octal_number) elif combo_box.get() == 'Quinary to Hexadecimal': quinary_to_hexadecimal(get_value) if is_quinary(get_value) and len(str(hexadecimal_number)) != 0: display_answer(hexadecimal_number)
def hexadecimal_to_binary(hexadecimal_number): '''Convert hexadecimal number to binary number To convert hexadecimal to binary, you need to first convert hexadecimal to decimal and obtained decimal to binary Step 1: Convert hexadecimal to decimal 123 = 1 * 16^2 + 2 * 16^1 + 3 * 16^0 = 291 (decimal number) Step 2: Convert the obtained decimal to binary 2 | 291 | 1 ------ 2 | 145 | 1 ------ 2 | 72 | 0 ------ 2 | 36 | 0 ------ 2 | 18 | 0 ------ 2 | 9 | 1 ------ 2 | 4 | 0 ------ 2 | 2 | 0 ------ 1 Required binary number is 100100011 (taking remainder in reverse order) ''' global binary_number decimal_number = 0 if is_hexadecimal(hexadecimal_number): if hexadecimal_number.isalpha() or not hexadecimal_number.isdigit(): split_hexadecimal = list(str(hexadecimal_number)) for index, split_hexa_decimal in enumerate(split_hexadecimal): if split_hexa_decimal.upper() in hex_to_num: split_hexadecimal[index] = hex_to_num[split_hexa_decimal.upper()] reverse_split_hexadecimal = split_hexadecimal[::-1] for index, value in enumerate(reverse_split_hexadecimal): decimal_number += int(reverse_split_hexadecimal[index]) * 16 ** index binary_number = decimal_to_binary(decimal_number) else: reversed_hexadecimal = hexadecimal_number[::-1] # Converting to decimal for x in range(len(reversed_hexadecimal)): decimal_number += int(reversed_hexadecimal[x]) * 16 ** x binary_number = decimal_to_binary(decimal_number) else: MessageBeep() display_answer('Invalid Hexadecimal Number')
def beep(disable=False): if not disable: MessageBeep()
def add_info(event=None): '''Get value from user and add/delete them''' get_values = [ name_box.get().strip().upper(), month_box.get(), date_box.get() ] if len(get_values[0]) == 0 or len( get_values[1]) == 0: # Check if the field is empty MessageBeep() show_info(message='Empty Field', pos_x=35, pos_y=415) name_box.delete(0, END) elif get_values[1] not in month_number or not get_values[-1].isdigit( ) or get_values[-1] == 'Select Date' or get_values[ 1] == 'Select Month': # Check entered date is not digit or alphabets MessageBeep() show_info(message='Invalid Date', pos_x=25, pos_y=415) elif int(get_values[-1]) > 32 or int( get_values[-1] ) == 0: # Check entered date is integer and between 01-32 MessageBeep() show_info(message='Invalid Date', pos_x=25, pos_y=415) elif var.get() != 1 and var.get() != 2: # Check if no buttons are selected MessageBeep() show_info(message='No button\nselected', pos_x=50, pos_y=400) else: check_for_folder() date = '{}-{}'.format(month_number[get_values[1]].zfill(2), get_values[-1].zfill(2)) if var.get() == 1: # Check if add button is selected if check_duplicate(get_values[0], date): # Check if input date already exists MessageBeep() show_info(message='Details Exists', pos_x=12, pos_y=415) else: # If not already in file with open('details.txt', 'a') as append: append.write('{}{}\n'.format(get_values[0].ljust(50), date)) show_info(message='Details Added', pos_x=17, pos_y=415) elif var.get() == 2: # Check if delete button is selected if not check_duplicate(get_values[0], date): # Check if entered value not in file MessageBeep() show_info(message='Invalid Details', pos_x=2, pos_y=415) else: # Check if entered value in file with open('details.txt', 'r+') as read_write_details: lines = read_write_details.readlines() # Reading file lines.remove('{}{}\n'.format(get_values[0].ljust(50), date)) read_write_details.seek(0) for line in lines: # Writing everything except details entered by user read_write_details.write(line) read_write_details.truncate() show_info(message='Details Deleted', pos_x=2, pos_y=415) sort_details()