Most voted "python-3.x" questions
Python 3 is the latest version of the Python programming language and was formally released on December 3, 2008.
Learn more…3,274 questions
Sort by count of
-
1
votes1
answer154
viewsImage does not open with Tkinter, how to solve?
I need this code to open an image in a label, but this error is returned: "Runtimeerror: Too Early to create image" from tkinter import * i = PhotoImage(file="ddddd.png") root = Tk() label =…
-
1
votes1
answer57
viewsRelationship Problems between "Table" and Django User
I am working with Django to develop an application for a Help Desk, I have the following situation: I have a table named "Unit" that will be the table responsible for separating my systems into 4 or…
-
1
votes2
answers2094
viewsOpen Python file only works with Windows folders in English
I have a Python program that asks the user for a file path and shows the contents of the file on the screen. The problem is that the code only works when I put the names of Windows folders in…
-
1
votes2
answers1086
viewsAdding list elements during a Python loop always returns the same value
I have the following code: current = [0, 1] someList = [] while True: for n in range(0, 2): current[n] += 1 print(current) # [1,2] and [2,3] someList.append(current) if current == [2, 3]: break…
-
1
votes3
answers212
viewsProblem with number guessing game
This number guessing game script doesn’t work, in part if z = "s" Python says the syntax is invalid. Someone could tell me why it doesn’t work, and what would be the right one? import random def…
-
1
votes1
answer85
viewsError running Python test 3.6.7
This gives error when running def test() to test def questao(). Why would be giving error in the return of the test function? def questao(): lista_nomes = [] nome = '' x = 0 reader =…
-
1
votes2
answers82
viewsReturning Added Data in a Dictionary
In my code I am asking the user to enter the note, n° of registration and frequency of 2 people. But I want to do this using dictionaries, so I declared the keys 'Nota', 'Matricula' and 'Freqüência'…
-
1
votes0
answers146
viewsTraveling Salesman - Exhaustive Algorithm
I need to create an algorithm that: 1. Discover all possible paths that visit all vertices of a graph without going through the same vertices twice. 2. Store all results. 3. Return the path with the…
-
1
votes2
answers361
viewsHow to create an array with value one?
Hello I would like to know if there is a way and which would be the most correct way to create a list (or an array) with the ones filled with the value 1 given the length of another list. Exactly…
-
1
votes2
answers616
viewsProblem showing image in imshow
I have a function that opens an image and sums with a random matrix but the function cv2.addWeighted generates the following error even though the types of the two matrices are equal : Traceback…
-
1
votes2
answers100
viewsRecursive program that accepts a non-negative integer as input and displays its vertically stacked digits
I developed the recursive function vertical(), which accepts a non-negative integer as input and displays its vertically stacked digits. For example: >>> vertical(3124) 3 1 2 4 Solution:…
-
1
votes2
answers75
viewsCounting the number of executed operations over the same input for a recursive call
idea: Compare a recursive version of the exponentiation implementation with a non-recursive version. Recursive version: def power(base,expoente): global cont if base == 1: return 1 elif expoente ==…
-
1
votes1
answer74
viewsDoubt in the book Python on a Crash Course
I’m studying the book Python on a Crash Course And everything was going great until now. After testing the codes on pages 324 and 325 (which are a module and a program that uses it), I was surprised…
-
1
votes1
answer347
viewsHow to remove the edge of a Pyqt5 window on Raspberry Pi?
I’m developing an application that will run on a Raspberry Pi interfaced in Pyqt5. This application will occupy the entire screen, making it impossible for the user to click outside the application.…
-
1
votes1
answer150
viewsLoop Problem and Time Calculation
I want to do a program, where he reads an activity, and the time spent on it. Example: Lavando o Portão, 10:30 as 12:00, tempo gasto 01:30 I am currently with 3 problems: The way my code is…
-
1
votes1
answer154
viewsExtracting email addresses from a web page using regular expressions in python
What I did: from urllib.request import urlopen from re import findall def emails(url): content = urlopen(url).read().decode() #print(content) padrao =…
-
1
votes2
answers548
viewsHow to convert the hash() value of a string back to the original string?
I’m learning now about Hashing and discovered that Python has a function called hash() that returns the hash value of an object. The problem is, how can I convert this value to my original object,…
-
1
votes3
answers1988
viewsEmail validation function
I need help with this code 'cause I’m racking my brain and I can’t fix it. You first enter the number of emails you want to enter with input. Then you type the emails according to the number you…
-
1
votes0
answers416
viewsHow to debug python in Visual Studio Code
I have the following structure and folders and files: DebugTeste |--br |--com |--empresa |--implementacao | |--__init__.py | |--Ola.py | |--testes |--testeOlaMundo __init__.py code: # __init__.py…
-
1
votes1
answer515
viewsHow to assign the PK of the logged-in user in Django to an FK in the model?
Hello, what I am trying to do is basically the following, I have in my application a Model called 'Shopping', and one of the fields of this Model is the user who registered the purchase, I want each…
-
1
votes1
answer247
viewsHow to sum the values of each element of 2 lists with List Comprehension
I have 2 lists and I want to add the element of each position on list a to the element of the same position on list b, only using <b>List Comprehension </b> a = [1,2,3,4] b = [5,6,7,8]…
python-3.xasked 4 years, 9 months ago Alisson Jonathan 23 -
1
votes1
answer167
viewsHow to make the window transparent background in Kivy
Hello, I am trying to make a program that creates a window without borders and with transparent background. The first part I got: Window.borderless = True But I haven’t been able to make the…
-
1
votes1
answer123
viewsThe program is not recognizing whole number as such
a = int (input ("insira um número :")) if a != int : print ("isto não é um numero inteiro") else : print ("seu número foi :"+ str(a)) I’m trying to make a program where the user puts a value and the…
-
1
votes1
answer77
viewsError importing database from Mnist
Good afternoon, I am trying to import a mnist dataset but when I enter this code: # importar as bibliotecas necessárias from sklearn.datasets import fetch_mldata import matplotlib.pyplot as plt…
-
1
votes1
answer1442
viewsPick a select value in Django
The HTML code: <!doctype html> <html lang="pt-br"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0,…
-
1
votes1
answer166
viewsSorted for Bhaskara formula
I have an exercise to solve and I have a problem, it is not to be done in list or dictionary. If you have 2 real roots they should be printed in ascending order, the problem is that you should print…
-
1
votes0
answers48
viewsWhat is the relationship and differences between Process and Thread?
I’m reading regarding the class Process and in the documentation it says that it follows the implementation of Threads, however, I have a question regarding the process class and threads. Doubts How…
-
1
votes2
answers422
viewsFinding students without a class - Python / Excel
I have a spreadsheet in Excel with all my students and their respective grades (5th to 9th). I need to find all my students who aren’t in any class. Through the Excel filter I can do, but I have…
-
1
votes0
answers1189
viewsError "Valueerror: operands could not be broadcast Together with shapes"
I’m getting this mistake: Traceback (Most recent call last): File "geraEstatistica.py", line 148, in cnplot = map.Contour(x,y,result,clevs,Cmap=plt.cm.jet) File…
-
1
votes2
answers379
viewsHow to search for partial text in a string list?
I have a list with several text elements, and I would like to know how I can find one of these elements by searching for a part of the text and not by the exact text. Example: Lista = ['Jorge…
-
1
votes3
answers354
viewsHow to hide sensitive information in Django?
In my Django project I have some sensitive variables, which I need to 'hide'. In general, save them in a file . env and read them with DADO_SENSIVEL = os.environ.get("DADO_SENSIVEL", default="")..…
-
1
votes1
answer155
viewsConvergencewarning in the Lasso CV method - What can I do to solve the problem?
Could someone help me with this mistake? Convergencewarning: Objective Did not converge. You Might want to Increase the number of iterations. Duality gap: 3.5998713265016704, tolerance:…
-
1
votes1
answer97
viewsSum variable is accumulating the value instead of starting at zero
The algorithm is for the customer to place orders in a snack bar, he asks for the name of the customer - 1, then the order quantity and then the algorithm asks to enter the order number, when the…
-
1
votes3
answers362
viewsFunctions with optional Python parameters
I want to create a function that has the first optional parameter. For example: the function range([start, ] stop [, step]) Thus, if only one argument is passed it is considered as the second…
-
1
votes1
answer157
viewsPython Code Numpy Arrays Creation Problem
I’m having trouble in the following code. I don’t understand what is wrong. I believe it is in the function sigmoid where she appears not to be receiving values float. import numpy as np # sigmoid…
-
1
votes1
answer39
viewsMultilayer Perceptron Two-Layer Code Problem
I have a problem with the following code: import numpy as np def nonlin(x,deriv=False): if(deriv==True): return x*(1-x) return 1/(1+np.exp(np.float32(-x))) X =…
-
1
votes1
answer52
views"except" does not recognize value as wrong
mensagem = input('''Clique "C" ''') print (mensagem) #condições relativas ao input mensagem try : mensagem == "C" except Exception : print ("a casa caiu") else : print ("a casa não caiu") The…
-
1
votes2
answers668
viewsProblems trying to access JSON file in Python
Hello, I’m trying to read certain data from a JSON file in Python, but I’m having some problems... This is the JSON file: { "linguagem":"Python", "dados":"JSON" } Implementing the JSON file directly…
-
1
votes0
answers38
viewsGroup by column-specific values in a Dataframe
I have the following dataset: Brand Condition Fuel 0 Toyota Used Diesel 1 Suzuki Used Petrol 2 Suzuki Used CNG 3 Suzuki Used Petrol 4 Toyota Used Petrol It’s over 10,000 records and has over 15…
-
1
votes3
answers165
viewsError with Random function
This is the code I wrote in Python: from random import randint a = randint print(a) When using the function randint in this simple code, the console gives me the following error: <bound method…
-
1
votes1
answer61
viewsFunction within a function
I’m doing some tests and I’d like to understand why when my role somadez() is called is returned to me that function soma() was not defined being that the same when it is called works. Follows the…
-
1
votes2
answers150
viewsRegular expression validation is invalid even when you find a match
I’d like to know what’s wrong with that code. All valid values I enter in the name, email and phone are invalid, even if in the format requested by regex. import re class Contato: def…
-
1
votes2
answers444
viewsVirtual Assistant
Good afternoon fellows, as you go? So I’m fairly new to this development environment and I programmed in python some time ago. I have a project idea where it involves creating a kind of virtual…
-
1
votes1
answer101
viewsData munging with python
Are the following date formats: 042555 04/25/1955 Abril 25, 1955 How to use regex to transform a date format into each other (would be 6 transformations)? For example: Entrada: 042555 Saída:…
-
1
votes2
answers143
viewsFind arrays with the shortest distance
I have a array_objetivo and would like to find the id and the distance (Euclidean in this example) of n arrays closer to him that are in array_all. Following are examples of arrays. array_objetivo =…
-
1
votes1
answer5585
viewsAttributeerror: 'Cursoprogramming' Object has no attribute '_valuations'
I’m developing a little Python "online course site" system, and there’s an error that, at least for me, doesn’t make sense. Follows the code: from src.site.classes_de_alunos_e_professores import…
-
1
votes2
answers94
viewsHow to name the keys of a dictionary from a list (array)?
If I have a dictionary of this kind: dados = {"indice1": [1, 2, 3], "indice2": [4, 5, 6]} and want to name its keys: indice1, indice2 with the following array: names= ['nome1', 'nome2'] I can do…
-
1
votes1
answer730
viewsRead a JSON file and print the data in tabular format
The file is "grids.json", whose structure is: {"students": [{"name": "Alan", "lastname": "Silva", "exam1": 50, "exam2": 80, "exam3": 91}, {"name": "Paula", "lastname": "Souza", "exam1": 95, "exam2":…
-
1
votes0
answers42
viewsReading Table in Python with Beautiful Soup
I need to get a table of the transparency portal to then write to the database. I am using Beautiful Soup. I can’t bring in the request the part that has the data and consequently no tag that I look…
-
1
votes1
answer490
viewsConvert function arguments to string
How to convert function arguments to string? Without having to type all arguments I tried to solve it this way: def teste(a, b, c, d, e='F9', f=1): for key, value in locals().items(): key =…