Posts by FourZeroFive • 1,231 points
61 posts
-
-4
votes1
answer92
viewsA: Assign Value to a variable that the user puts C#
You need to convert what is typed to int first, here I used the function Convert.ToInt32() string nome; int idade; Console.WriteLine("Insira seu nome: "); nome = Console.ReadLine();…
-
-3
votes3
answers248
viewsA: Regex - take only the first occurrence of a word in Python?
Use re.search(), works a little differently, follows the example: import re print(re.findall(r'primeiro',' o primeiro o segundo primeiro novamente')) print("\n") print(re.search(r'primeiro',' o…
-
0
votes1
answer40
viewsA: problem with None
The problem occurs because the function has no return to the print, when the code hits the break, the solution would be to add a return in the function, for example: def alphabet (s,t,k): for i in…
pythonanswered FourZeroFive 1,231 -
11
votes5
answers1031
viewsA: Check that all items in the list are equal
One way you can do it is the set(), where when a list is converted to a set, duplicate elements are removed, so if duplicates are removed, the size of that set is 1, implying that all are equal,…
-
0
votes1
answer89
viewsA: Buffer Overflow
Well, I’m starting from the concept that you understand what a buffer overflow is. On the first question: When you use the function strcpy() you copy all content from one variable to another,…
-
1
votes1
answer248
viewsA: Why do I get this error on locale. h? [Error] expected declaration specifiers or '...' before Numeric Constant
As @anonimo quoted, setlocale() needs to be inside the main(), or some other function, and I speculate that one of the factors below are related to this error. The setlocale(LC_ALL, "C"); be…
-
0
votes1
answer37
viewsA: Python - Error entering STR given in FLOAT or INT
You can do it on condition try-catch: try: numeroInteiro = int(input("Insira um numero inteiro: ")) except ValueError: print("Você deve inserir um valor inteiro!") As you can also do for…
pythonanswered FourZeroFive 1,231 -
1
votes1
answer118
viewsA: Is there any way to run the bash script in windows?
Due to the fact that Microsoft operates Azure, and because it is a cloud service, it was necessary to implement bash in Windows 10, even though it is still in beta phase. So to gain access to…
bashanswered FourZeroFive 1,231 -
0
votes1
answer30
viewsA: Read files in c
The fact that the program does not read what it has after space, is linked to the fact that you use the format specifier %s ,which is bounded by the space, that is, of the string "Fulano de Tal", he…
canswered FourZeroFive 1,231 -
2
votes3
answers82
viewsA: How do I differentiate an int and float value for my program
You can use: try: numeroInteiro = int(input("Insira um numero inteiro: ")) except ValueError: print("Você deve inserir um valor inteiro!") If the user enters anything other than an integer, it will…
pythonanswered FourZeroFive 1,231 -
2
votes2
answers78
viewsA: Doubt replace in pandas
The problem is that when you do df['nova_coluna'] = df.texto.str.replace(palavra, '') you are changing the original text all the time, ie an iteration you remove 'computers' and not saved, then…
-
1
votes2
answers43
viewsA: doubts in the creation of dataframe pandas
This problem of yours can be done in two ways: import pandas as pd dicionario = {'pais': 'brasil', 'capital': 'brasilia', 'clima': 'tropical'} pd.DataFrame([dicionario]) print(dicionario)…
-
0
votes2
answers59
viewsA: Access a matrix in the function
There are other ways to solve the problem, and mine was: functions. #include <iostream> template <size_t rows, size_t cols> void sum(float (&A)[rows][cols]) { float v[rows]; size_t…
-
-2
votes1
answer41
viewsQ: How to serialize a Hash object from Hashlib for Socket submission?
How is it possible to serialize an object of the type _hashlib.HASH , so that it is suitable for sending via sockets (sendall() and send()) ? With the pickle is made: hashed_Message =…
-
-1
votes1
answer179
viewsQ: Sending a C++ vector to a Python function
I have the following function written in python in a file. py: def coordinate(arg): print arg return True And an example of C++ code in a file. CPP #include <Python.h> #include <vector>…
-
4
votes7
answers1969
viewsA: How to remove repeated numbers from a python list
numeros = (input("Digite uma lista com números inteiros: ")) lista = numeros.split() # transforma em listas print("Você digitou os seguintes números: ") print(lista) def remove_repetidos(lista):…
-
0
votes2
answers143
viewsA: Random Hoice and shuffle with different behaviors
I guess you didn’t read the paperwork: shuffle() : Randomize the values in the positions of the list itself, ie return in the list itself, which in this case is alunos, running twice for example,…
-
0
votes1
answer675
viewsA: Multi-line comments and Python identation error
In Python the only thing made to comment code is the # , what are you doing using ''' is just a literal string, meaning a docstring, the same serves to comment, but it must also be alive, as in the…
-
4
votes1
answer168
viewsA: Bash write output in terminal and file
From what I understand your question, you could do it through command tee that does what is in the image below, obtained from this website: Passes command and it saves in the file and plays on…
-
2
votes2
answers71
viewsA: Object array gives error when I try to access an element of it
Solution: public static void main(String[] args) { Olho[] ol = new Olho[2]; ol[0] = new Olho("Castanho",true); ol[1] = new Olho("Azul",false); ol[0].verificar(); } Note that in the code you passed,…
-
1
votes1
answer32
viewsQ: How to write a variable Std::vector<Std::tuple<>> into a txt file?
I have the tuple vector written in C++, defined as: std::vector<std::tuple< float, float>> ASK_Mod; I populated it, and tried to save it in a new file . txt as defined in the function,…
-
0
votes1
answer60
viewsA: How to know the intensity of pixels in a given row or column of a cv::Mat?? [opencv][c++]
Okay, I’ll try to answer, but I have no way to test it, so: First in class: class fooTools { public: static std::vector<uchar> intensity(cv::Mat src, int ref, std::string lico); }; Due to the…
-
4
votes2
answers158
viewsA: What happens to memory when "realloc()" reallocates a memory block to a value less than the original?
I don’t know if I’ll be able to answer your question, but come on.. What happens to memory when realloc realoca a block of memory for a value less than the original? Simply the realloc() will make a…
-
1
votes1
answer122
viewsA: Opencv c ++ how to display a text (letter) on the webcam in c++?
So describing succinctly, without treating the possibility of failure, as empty frame or the camera has not been opened, together with the answer to the question, we have: // Inicializa a camera…
-
1
votes1
answer158
viewsA: Matrix Loop with multiple vectors: Pyhton
It’s very quiet to do, just need to initialize an array of zeros of the size you want and then go filling in with the values you get. import numpy as np Matriz = np.zeros((24,1)) # Inicializa a…
-
2
votes1
answer285
viewsQ: Combine multiple Regular Expressions into one
Is there any way to combine multiple regex patterns into a single expression, to be used in re.match() or re.search(), for example? starts_with_Y = '([Y][A-Za-z0-9]{6}([-][A-Za-z0-9]{1})?\s)'…
-
2
votes3
answers98
viewsA: Conditional structure and repetition For simple in C
You used the assignment operator = at the place of the comparison operator == us if, for this reason happens the problem. #include <stdio.h> int main() { int c1,c2,ops; printf("Digite um…
canswered FourZeroFive 1,231 -
1
votes1
answer939
viewsA: Measure the use of Python code in the CPU and Memory
If you are not using task manager, you can use psutils library import psutil print(psutil.cpu_percent()) # Em porcentagem, uso da CPU print(psutil.virtual_memory()._asdict()) # Em dicionário…
python-3.xanswered FourZeroFive 1,231 -
3
votes2
answers141
viewsA: connect python 3x to a server
import socket target_host = 'www.google.com' target_port = 80 #criar um objeto socket client = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #conectar o cliente…
-
-1
votes2
answers79
viewsA: Command imread() and iteration
import os import cv2 imagem_array = [] diretorio_pasta = "sua pasta de imagens aqui" for imagem_dir in os.listdir(diretorio_pasta): try: imagem_array.append(cv2.imread(imagem_dir)) except Exception…
-
1
votes1
answer2855
viewsA: Make VS Code find module installed by Pip command on linux
Apparently the Pip command installed relative to Python 2, so I ran the sudo apt-get install python3-pip Then ran Pip specific for Python 3 pip3 install pyserial Then VS Code recognized…
-
1
votes1
answer2855
viewsQ: Make VS Code find module installed by Pip command on linux
I installed matplotlib by sudo apt-get and VS Code was able to find the library automatically, however with pyserial by Pip command, VS Code cannot find, as I should do?
-
5
votes1
answer109
viewsA: What is the functionality of this line of code?
All right, let’s go ser.write() is for "write" on serial port. str() is to convert the value to string. dataDict[] is a dictionary. "\n" is to skip a line. encode() is to convert to a set in bytes…
-
0
votes2
answers85
viewsA: Text manipulation error with Python
Your problem occurs due to the use of ;, Python does not use it, it is correct to use the : when necessary, its code has not even been tested whole, because the interpreter is already stopping at:…
pythonanswered FourZeroFive 1,231 -
1
votes3
answers4406
viewsA: How to comment on python3
You can comment lines using # # print("Isso não vai imprimir") You can comment blocks using ''' ''' print("Esse bloco não vai executar") '''…
-
2
votes2
answers264
viewsA: How to round decimal numbers to the largest integer? python
Import the library math, and in it there are two functions, the floor() and the ceil(), to floor() rounds down and the ceil() rounded up to the nearest integer math.floor(30.4) (30.0)…
-
0
votes1
answer481
viewsA: Python script with a peculiar if and Else condition problem
Friend, it happens because of the nature of your if's, one of them is whether the variable is 'N' and the other is whether the variable is not 'N', that is, if I press 'N' the first if will be true,…
pythonanswered FourZeroFive 1,231 -
0
votes1
answer58
viewsA: Read line by line file
#include <string> #include <fstream> #include <iostream> std::ifstream arquivo( "teste.txt" ); # Seleciona o arquivo std::string linha; # String linha int main() {…
c++answered FourZeroFive 1,231 -
1
votes1
answer236
viewsA: Repetition for command exercise in python
Friend your code has some problems besides that is unused, your comparison of results has a space before the name and are still in lowercase, you just forgot you used the function str.upper(), then…
pythonanswered FourZeroFive 1,231 -
2
votes4
answers2298
viewsA: Printing a number odd sequence on a list
impares = [] number = int (input()) for numero in range(0,number): if(numero % 2 != 0): impares.append(numero) print(impares[::-1]) It is not necessary to use list(), follow this link to understand…
-
0
votes1
answer136
viewsA: Problem with while C++
#include<iostream> #include<vector> int main() { std::vector<int> valores; // Declara vetor de int for(int k = 0; k <= 4; k++) // Grava 5 número no vetor valores { int temp;…
c++answered FourZeroFive 1,231 -
2
votes1
answer42
viewsQ: Regex for two string hypotheses simultaneously
I have the following input, and I do a line-by-line interaction at all. D b1308 pspE; thiosulfate sulfurtransferase PspE K03972 pspE; phage shock protein E B 09193 Unclassified: signaling and…
regexasked FourZeroFive 1,231 -
1
votes1
answer259
viewsA: Logical error when sorting vector in pair and odd
Your code was correct, except for one detail in for chained. #include <stdio.h> int main() { int vector[10]; int aux = 0; printf("Digite 10 numeros a serem ordenados em par e impar:\n"); for…
-
0
votes3
answers550
viewsA: Input jumps line, how not to jump in Python?
Look your question is not very clear to me yet, but from what I understand you want this. linha = '' inseridos = [] while True: if linha != 'ABC': linha = input("Insira string\n")…
pythonanswered FourZeroFive 1,231 -
0
votes1
answer485
viewsA: How can I use Scrapy in Anaconda
So first, you must run the Anaconda Prompt as administrator, set by the command cd the directory you want to save the project and then create the project by the command scrapy startproject your…
-
3
votes1
answer169
viewsQ: What does Transition band mean in band-pass filters?
Hello, I am working on a band pass filter in python, and while searching I found this link, which states a code variable: "b is the transition band also as a function of the sampling rate" What does…
-
1
votes1
answer92
viewsQ: Logic of a neural network implementation
Hello, Good Morning I implemented a network, and it has the following matrix, where f(x) is an input vector (Matrix 1,139), the Phi matrix that has dimension 1,20 (20 due to the number of signals I…
-
-1
votes1
answer93
viewsQ: Language for Backend and another in Frontend?
I have a desktop program without GUI working in Python, I would like to add a GUI using another language mainly one with some visual editor ,C++ for example, to be a frontend, would that be…
pythonasked FourZeroFive 1,231 -
0
votes2
answers1164
viewsA: Save data to a csv file
I don’t remember if writelines works with variables, but basically that’s it. fh = open(“contatos.csv”,”w”) linhas_de_texto = [camp1, camp2, camp3] fh.writelines(linhas_de_texto) fh.close() You were…
pythonanswered FourZeroFive 1,231 -
1
votes2
answers1540
viewsQ: Transforming vectors into a Matrix
I have several signals, where S1, s2 until Sn, are vectors of size n, I would like to unite them in a matrix to stay as follows: matriz = ( [s1] [s2] ... [sn] ) So that I can access an element at…