Posts by Lacobus • 13,510 points
596 posts
-
0
votes1
answer135
viewsA: subtraction of numbers from 32 to 64
.intel_syntax noprefix .comm diff64, 8, 8 # Declara simbolo de 64 bits MOV EBX, 87654321 # Minuendo em EBX MOV EAX, 12345678 # Subtraendo em EAX SUB EBX, EAX # Subtrai…
-
1
votes2
answers467
viewsA: Duplicate Select Postgresql output
Assuming: CREATE TABLE tb_recibos ( codigo integer, cliente text, valor integer, emitente text, data date ); INSERT INTO tb_recibos ( codigo, cliente, valor, emitente, data ) VALUES ( 1, 'Fulano',…
-
2
votes2
answers1145
viewsA: Python object datetime value extraction.
Using the method strftime() with formatting %H and returning string: from datetime import datetime obj = datetime.now() hora = datetime.strftime( obj, "%H") print(hora) Using the attribute hour of…
-
0
votes1
answer32
viewsA: Segmentation float when starting the function for the second time
Avoid including files .cpp in your fonts, this causes a mess without size! Create a settings file .h containing the prototypes of the functions and include it. matrix. h: #ifndef __MATRIZ_H__…
-
3
votes1
answer4772
viewsA: Create a dictionary from a list
You can scan the list by scanning items prefixed with CAD, PAG or LIB. If the item has any of the prefixes, a new key is included in a dictionary and its value (a list) is filled in until a new key…
-
2
votes1
answer6285
viewsA: Python prime numbers | while
def ehPrimo(x): if x >= 2: for y in range( 2, x ): if not ( x % y ): return False else: return False return True num = int(input("Entre com um…
-
1
votes1
answer53
viewsA: is repeating only once
You don’t need two ties to solve the problem, only one is enough: #include <iomanip> #include <iostream> int main(void) { std::time_t now = std::time(nullptr); std::string lang[6] = {…
-
1
votes3
answers218
viewsA: Dictionary does not return all possible words
If the intention is to write your own comparison function of strings avoiding the use of family functions strcmp(), I suggest you modify your function compString() for something like: bool…
-
2
votes3
answers2562
viewsA: Sum the values of a Count(*) in sql
You can use UNION to unite the count of Aeroportos in each country with the total amount of Aeroportos in the same query (without any subselect): (SELECT a.Pais AS Pais, count(1) FROM Aeroportos a…
-
0
votes3
answers3451
viewsA: How to count the records of a csv in python?
To get the count of lines that have the occurrence "Female" in a given file, you can do something like: nlinhas = 0 with open('teste.csv') as arquivo: for linha in arquivo: if "Feminino" in linha:…
-
1
votes1
answer4040
viewsA: How to show accented characters in Visual Studio 2017 using C++?
The call of setlocale( LC_ALL, "" ); (with the second blank parameter), causes the default locale of the program to be set according to the variables of its environment, which certainly uses the…
-
1
votes1
answer319
viewsA: Code in C displays error "Segmentation failure (recorded core image)"
Don’t ignore the warnings compiler! Certainly, when compiling the question code, the compiler issued a Warning warning that the second parameter of scanf() is not compatible with the conversion…
-
2
votes1
answer2223
viewsA: How to view contents of a file . bin generated in c
Converter: #include <stdio.h> #define MAX_BUF_LEN 100 int main( int argc, char * argv[] ) { FILE * fin = NULL; FILE * fout = NULL; char buf[ MAX_BUF_LEN ] = {0}; int nlinha = 1; int n = 0; int…
-
1
votes2
answers104
viewsA: using any in python
You can convert your dictionary to a set in order to facilitate operations if subtraction between lists of dictionaries: from datetime import date l1 = ['0169924233316','01687665544','01978553322']…
-
1
votes2
answers49
viewsA: How to receive more than one user command at once?
How about: from datetime import datetime nasc = input("Informe sua data de nascimento: ") try: obj = datetime.strptime( nasc, '%d%m%Y') except ValueError: obj = None if obj: print("Data Completa:…
-
2
votes2
answers338
viewsA: Error when assigning variable value to vector in C
In C, it is not possible to copy the contents of buffers containing strings ended in \0 (array types) using the allocation operator =. The header pattern string.h provides a complete interface for…
-
2
votes2
answers9721
viewsA: How to find specific words in a python txt file?
You can build a simple state machine that performs a line-by-line search of a given input file, searching for the name or one of the person’s surnames. When finding a search-compatible person, the…
-
4
votes2
answers275
viewsA: Determine how many "islands" a matrix contains
You can use an algorithm known as Flood Fill with 8 recursive directions to flood all the islands in its matrix. The matrix is scanned cell by cell looking for flood islands. For each flooded…
-
2
votes2
answers2800
viewsA: How to get the records from the last 15 days - Postgresql
Recovers the records contained in the table public.entrega who own the field data completed with dates of the last 15 days, without considering future dates. SELECT * FROM public.entrega WHERE data…
-
1
votes1
answer1335
viewsA: Convert word(DOC) document to pdf using python
Follows the same code commented for a better understanding: doc2pdf.py: import sys import os import comtypes.client # Codigo correspondente ao formato .pdf wdFormatPDF = 17 # Recupera o path…
-
0
votes1
answer73
viewsA: How to apply recursive action to csv.Dictreader
You came very close to solving the problem, however, lacked attention in relation to indentation. In Python this is crucial and delimits code blocks. Follows a solution: import csv import os with…
-
2
votes1
answer263
viewsA: Euro banknote sorting program? Python
Comparisons between type values float are hell! Avoid them! Isolating your infinite loop: x = 10.5; while x > 0.0: x = x % 3 Instead of working with Euros, try working with Centimos by…
-
0
votes1
answer122
viewsA: Fill matrix with ZERO in null spaces, (python/Django)
If the variables somatorio.3 and somatorio.2 are presenting the value None, you can use the filter default_if_none to translate them to zero. In your case it would look like this: <td…
-
1
votes2
answers528
viewsA: generate id Session/secure php cookie
It follows a code capable of generating a 512-bit identifier (128 characters based on 16 or hexadecimal), from the name of the user, the local time of the system, the process identifier and a random…
-
2
votes2
answers1978
viewsA: How to count the number of "Rows" in a python table
Creating database containing a player table with 3 records: import sqlite3 jogadores = [ { "id" : 1, "nome" : "Joao" }, { "id" : 2, "nome" : "Maria" }, { "id" : 3, "nome" : "Jesus" } ] conn =…
-
1
votes2
answers76
viewsA: C++, Program does not resolve all Instances!
Your code is correct and will work as stated. However, as this is an academic work, I believe the intent of the problem is that the first-degree equation involving the calculation of percentages is…
-
1
votes5
answers988
viewsA: Error Split by 0
Divisions by zero throw a type exception ZeroDivisionError, that can captured with raise and translated into a Float::NaN (Not A Number), look at you: def calculo(operacao, x, y) if operacao ==…
-
7
votes2
answers1221
viewsA: C: error in srand(time(NULL);
The inclusion of headers: #include <stdlib.h> /* rand(), srand() */ #include <time.h> /* time() */
-
0
votes2
answers305
viewsA: Hide bombs in a minefield with ASCII 2
In C, to compare the equality between two integer values it is necessary to use the equal operator ==. You are using the assignment operator = in your comparisons and this will not work as you…
-
6
votes2
answers44
viewsA: How to print only values other than 0
You can use the conversion specifier %g to solve your problem: #include <stdio.h> int main(void) { printf( "%g\n", 2.560 ); printf( "%g\n", 5.000 ); printf( "%g\n", 3.600 ); printf( "%g\n",…
-
1
votes1
answer88
viewsA: Error using np.concatenate
Replacing: np.concatenate(resultado,esquerda[i:]) ... np.concatenate(resultado,direita[:j]) For: np.concatenate([resultado,esquerda[i:]]) ... np.concatenate([resultado,direita[:j]]) ...and with a…
-
2
votes2
answers409
viewsA: How does Python keep the same memory reference as a list after resizing it?
The function id() returns a unique identifier of an object instance. When resizing a list, although the object changes in its internal state, the instance remains the same, which makes it id()…
-
0
votes1
answer6433
viewsA: Python local and global variables
How about: import datetime import easygui # Declara lista global contendo o intervalo de datas e um flag indicador g_intervalo_data = [ False, None, None ] def ValidaData( data ): try:…
-
0
votes4
answers106
viewsA: What’s wrong with my class function to diminish the value?
Comparisons with floating point numbers are hell! Avoid them! In this case, you can avoid all these comparisons by pre-calculating in a array the values within the desired range. Increment and…
-
0
votes1
answer76
viewsA: My code Builds always incorporate Python 2.7 instead of 3.6, how to resolve?
The executable binary of Python version 2.7 usually has no suffix: $ python --version Python 2.7.5 The executable binary of Python version 3.x has suffix to avoid conflicts: $ python3 --version…
-
0
votes1
answer39
viewsA: Graph with values of 2 in 2dB
How about: import matplotlib.pyplot as plt ber_teorico=[ 0.158655253931, 0.130927296756, 0.104028637085, 0.0788958719817, 0.0564953017494, 0.0376789881475, 0.0230071388779, 0.0125870331221,…
-
2
votes1
answer140
viewsA: Save amount of occurrences of a txt file to another python txt file
Dictionaries do not have ordination in Python! The secret is to convert the dictionary to a list of tuples and then sort it: from collections import Counter # Abre arquivo de Entrada para leitura…
-
4
votes1
answer880
viewsA: View all values of an array
Numpy Arrays often "summarize" the display of large content and control this by setting up a threshold (limit) which can be set by the method set_printoptions(). For the display of a Numpy Array…
-
0
votes1
answer8585
viewsA: Indexerror: index 3 is out of Bounds for Axis 0 with size 3
The range used in your loop for k in range( 3, tf ) is extrapolating the limit of your Numpy Array x already in the first iteration. Your Numpy Array was initialized with only 3 elements: x = 2…
-
1
votes3
answers719
viewsA: Why static methods can be called through the "instance" of the Python 3 class?
Class methods marked with @staticmethod are considered static, i.e., do not depend on an instance of the object to be called. However, this does not mean that calling static methods through an…
-
1
votes1
answer1588
viewsA: Manipulating python text files
The file needs to be opened using the mode wr+, which allows read and write operations via the file descriptor, You can use the method seek() descriptor to return the file cursor to the beginning,…
-
1
votes1
answer112
viewsA: Overload of the Sort method
Use the Slice Notation to copy and clean your list self.pessoas: def sort(self): copia = self.pessoas[:] tamanho = len(self.pessoas) self.pessoas[:] = [] while len(self.pessoas) < tamanho:…
-
6
votes3
answers1488
viewsA: Using Lower() in a list of lists in Python
You can use the package NumPy to convert multidimensional lists without losing the original list dimensions: import numpy as np def list_lower( lst ): aux = np.array(lst) for i, v in np.ndenumerate(…
-
5
votes2
answers997
viewsA: Manipulating lists in Python
Solution #1: Lista_A = [['de','do','da','ou'],['ae','ay','yhh','oo'],['ow','pa','la','for']] Lista_A_new = [item for sublista in Lista_A for item in sublista] print(Lista_A_new) Solution #2: Lista_A…
-
1
votes2
answers168
viewsA: List entry with sequential search
How about: def preencheLista( lst, tam ): for i in range(tam): while True: c = float( input("Entre com o termo: ") ) if c in lst: print ("Valor ja existente, digite um novo valor!") continue;…
-
3
votes2
answers195
viewsA: Find the problem in my Python object list
This whole complexity is not necessary when you are programming in Python! This simple program is able to return what you want: from collections import Counter arquivos = [ 'texto1.txt',…
-
1
votes1
answer435
viewsA: Quicksort in ascending order in Python
Dictionaries have no ordering. The function collections.Counter() returns a dictionary. The secret to ordering dictionaries is to convert them to a list of tuples and then sort them. With a small…
-
1
votes2
answers70
viewsA: Undefined Reference to `Teste_1::Teste_1
Tip #1: Whenever a .h or a .cpp have external references, the header of this external reference should be included. This increases decoupling between modules and improves code readability.…
-
3
votes3
answers309
viewsA: Fibonacci sequence does not work
You can work with the type unsigned long long which has the size of 64bits, making it possible to generate Fibonacci sequences of up to 91 numbers: #include <stdio.h> #include <stdlib.h>…
-
3
votes2
answers478
viewsA: Reading list of integers from a binary file
Generating file with 128 bytes with random data for testing, which represents 32 integers of 4 bytes: $ head -c 128 < /dev/urandom > randomnumbers.bin Generated file: $ xxd randomnumbers.bin…