def determine_increment(folder): filenames = listdir(folder) indexes = [ int(filename.split("_")[0]) for filename in filenames if isnumeric(filename.split("_")[0]) ] return min(indexes)
def _get_last_num(self, stri): num = "" for el in stri[::-1]: if isnumeric(el): num += el else: break return num[::-1]
def _get_last_num(self, stri): num = "" for el in stri[::-1]: if isnumeric(el): num += el else: break return num[::-1]
def isNum(s): if isnumeric(s): return True else: try: float(s) return True except ValueError: return False
def multiplayer(): playerOneTurn = True while 1: printTable() if playerOneTurn: print("Player 1:") inp = input() if isnumeric(inp): a = int(inp) if a in range(1, 10) and choices[a - 1] == ' ': choices[a - 1] = 'X' playerOneTurn = False else: print("Ivalid move") else: print("Ivalid move") else: print("Player 2:") inp = input() if isnumeric(inp): a = int(inp) if a in range(1, 10) and choices[a - 1] == ' ': choices[a - 1] = 'O' playerOneTurn = True else: print("Ivalid move") else: print("Ivalid move") if checkWinn() == 1: print("Player 1 wins!!") break if checkWinn() == 2: print("Player 2 wins!!") break if checkWinn() == 0: print("Match draw!!") break printTable()
def get_answer_key(self): while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() quit() elif event.type == pygame.KEYDOWN: if isnumeric(pygame.key.name(event.key)) and int( pygame.key.name(event.key)) in range( 1, len(self.answers) + 1): return pygame.key.name(event.key)
def downloadGoogle(ticker, exchange, period, symbols=stockConfig.googleSymbols, interval=stockConfig.googleInterval, googleApi=stockConfig.googleAPI, track=0): url = googleApi + 'q=' + ticker + '&i=' + str(interval) + '&p=' + period + '&f=' + symbols + '&x=' + exchange # response = requests.get(url) cntCheck = 0 check = 'nope' while check == 'nope': data, track = tryRequest(url=url, typ='get', track=track) if (data.shape[0] <= 7) | ((data.shape[0] <= 8) & any(pd.Series(data).str.contains('DATA_SESSIONS'))): return None, track if any(pd.Series(data).str.contains('COLUMNS')): check = 'fine' if any(pd.Series(data).str.contains('Your client does not have permission to get URL')): time.sleep(60 * 60) cntCheck += 1 if cntCheck == 5: print(data) raise Exception('google data doesnt have columns but still passed tests, debug data output above') '''while loop that does the above if and then tests that 'COLUMNS' is in the data as it is breaking because values has not been set''' dataOut = [] for i in range(data.shape[0]): if data[i][:1] == 'a' or isnumeric(data[i][:1]).tolist() or 'COLUMNS' in data[i]: splitRow = re.split(',|=', data[i]) if 'COLUMNS' in splitRow[0]: values = splitRow[1:] elif splitRow[0][:1] == 'a': timeStamp = np.datetime64(datetime.fromtimestamp(int(splitRow[0].replace('a', ''))).isoformat()) splitRow[0] = str(timeStamp.astype(datetime)) dataOut.append(splitRow) else: splitRow[0] = str((timeStamp + int(interval) * int(splitRow[0])).astype(datetime)) dataOut.append(splitRow) dataOut = pd.DataFrame(dataOut) values[0] = 'timestamp' values = np.array([x.lower() for x in values]) dataOut.columns = values cols = ['timestamp', 'open', 'close', 'high', 'low', 'volume'] dataOut = dataOut[cols + values[np.array((~pd.Series(values).isin(cols)).tolist())].tolist()] dataOut.iloc[:, 1:len(dataOut.columns)] = dataOut.iloc[:, 1:len(dataOut.columns)].astype(np.float) dataOut['ticker'] = ticker return dataOut, track
def playerTwo(): playerOneTurn = True while 1: printTable() if playerOneTurn: print("CPU's Chance:") #INP A RANDON NO. IN THE NON SELECTED ARRAY arra = [] for i in range(9): if choices[i] == ' ': arra.append((int(i) + 1)) inp = random.choice(arra) print(inp) choices[inp - 1] = 'X' playerOneTurn = False else: print("Your Chance:") inp = input() if isnumeric(inp): a = int(inp) if a in range(1, 10) and choices[a - 1] == ' ': choices[a - 1] = 'O' playerOneTurn = True else: print("Ivalid move") else: print("Ivalid move") playerOneTurn = True if checkWinn() == 1: print("CPU wins!!") break if checkWinn() == 2: print("You win!!") break if checkWinn() == 0: print("Match draw!!") break printTable()
def check_for_numbers(item): if item[0] == '-': if len(item) > 1: if not isnumeric(item[1]): return 'process_further' if item[0] == '+': if len(item) > 1: if not isnumeric(item[1]): return 'process_further' if isnumeric(item[0]): if len(item) > 1: if not isnumeric(item[1]): return 'process_further' ##if first is + or - if not isnumeric(item[0]): if len(item) > 1: if not isnumeric(item[1]): return 'process_further' # ## check if every single char is numeric # for char in item: # if not isnumeric(char): # print(f'found char not number-----------') # return 'process_further' item_len = len(item) counter = 0 new_item = '' while (item_len): if item[counter] == '0': item_str = 'null' else: item_str = item[counter] if item_len == 1: new_item = new_item + item_str else: new_item = new_item + item_str + ' ' item_len -= 1 counter += 1 return new_item
def execute_character_movement(event_key, character_info_view, fields): old_x = character_info_view.character_info.x old_y = character_info_view.character_info.y move_keys = { K_w: (0, -1, Direction.NORTH), K_a: (-1, 0, Direction.WEST), K_d: (1, 0, Direction.EAST), K_s: (0, 1, Direction.SOUTH) } if event_key in move_keys.keys(): x = character_info_view.character_info.x + move_keys[event_key][0] y = character_info_view.character_info.y + move_keys[event_key][1] direction = move_keys[event_key][2] token = fields[x][y].get_token() if token is not None: result = token.interact(character_info_view.character_info) if result: if hasattr(token, 'item'): if token.item is not None: fields[x][y].put_item(token.item) fields[x][y].remove_token() Screen.Screen.display_map() character_info_view.display() elif CharacterController.check_if_passable(fields[x][y]): character_info_view.character_info.x = x character_info_view.character_info.y = y character_info_view.character_info.direction = direction Screen.Screen.render_character( old_x, old_y, x, y, character_info_view.character_img, direction) fields[x][y].interact(character_info_view.character_info) character_info_view.display() elif isinstance(fields[x][y], GateField): keys_ids = [ x.id for x in character_info_view.character_info.items if isinstance(x, Key) ] if fields[x][y].key_id in keys_ids: character_info_view.character_info.remove_key( fields[x][y].key_id) fields[x][y] = RoadField() Screen.Screen.display_map() character_info_view.display() elif event_key == K_e: field = fields[character_info_view.character_info.x][ character_info_view.character_info.y] if field.item is not None: item = field.get_item() if not character_info_view.character_info.add_item(item): field.put_item(item) Screen.Screen.render_text_values_for_n_seconds( character_info_view, 'You can\'t have any more items.', 700, 0, 800, 0) character_info_view.display() elif isnumeric(pygame.key.name(event_key)) \ and int(pygame.key.name(event_key)) in range(1, len(character_info_view.character_info.items) + 1): item_number = int(pygame.key.name(event_key)) - 1 item = character_info_view.character_info.items[item_number] if fields[character_info_view.character_info.x][ character_info_view.character_info.y].item is None: character_info_view.character_info.remove_item(item) fields[character_info_view.character_info.x][ character_info_view.character_info.y].put_item(item) Screen.Screen.repaint_screen() Screen.Screen.display_character_info(character_info_view) else: Screen.Screen.render_text_values_for_n_seconds( character_info_view, 'This field is already occupied by another item', 700, 0, 800, 0) elif event_key == K_r: fields[character_info_view.character_info.x][ character_info_view.character_info.y].interact() elif event_key == K_m: healing_item = character_info_view.character_info.find_healing_item( ) if healing_item: if not character_info_view.character_info.heal_with_item( healing_item): text = "Your health is excellent! There's no need to heal" else: text = 'You have been healed!' Screen.Screen.render_text_values_for_n_seconds( character_info_view, text, 700, 0, 800, 0) elif event_key == K_h: from controllers.ManualController import ManualController controller = ManualController() controller.display_manual() Screen.Screen.display_map() Screen.Screen.display_character_info(character_info_view)
def leiaDinheiro(valor): while True: if isnumeric(valor): break else: print('Digite um valor valido')