Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
-3
votes1
answer253
viewsHow do I wipe the memory to avoid overloading?
As you read the HTML of the site, go deleting what is before. If there is any clear screen in Python. import mechanize response = mechanize.urlopen("https://www.exemplo.com") m = 0 linha = '' if (m…
-
-3
votes1
answer97
viewsError in def function
How can I calculate salary value with number of hours above 40 as defined in the if, I try to run with 41 hours but gives me this error salario = float(40*valor_hora+(h_excd*(1.5*valor_hora)))#valor…
-
-3
votes2
answers415
viewsCall list in function in python 3
I am creating a script for my python course. The script takes as input a sequence of integer numbers terminated by zero and returns the numbers in ascending order, removing the repeated ones. The…
-
-3
votes1
answer492
viewsScript that takes a list of integer numbers, sorts and removes duplicates
I’m taking a course in python and I’m trying to solve the following exercise: Exercise 1 - Removing repeated elements Write the remove_repeated function that takes as a parameter a list of integer…
-
-3
votes1
answer76
viewsDiagonal name display (Up to Down)
I have to read a name and display it diagonally, that is, from top to bottom. But I’m not getting the logic right, I’ve come to this: nome = input('Digite o seu nome: ') tamanho = len(nome) for nome…
-
-3
votes1
answer33
viewsRaspberry Pi lights the wrong led
I am making a practical experience in which I turn on a green led or an red as the result of a question. I’m sure it’s not the circuits' problem, because I’ve tried it in many ways and it’s always…
-
-3
votes1
answer107
viewsUsing Math Tricks, can you speed up Python accounts?
An example of code about my doubt. %timeit lambda : 10000000000000000*10000000000000000 40.4 ns ± 0.592 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each) %timeit lambda :…
-
-3
votes2
answers127
viewsHow to write the condition "if not A" more explicitly?
How can I represent the notation if not A as a if A != B OR if A == B? In the case in point, I was working with string And I ran some tests with no effect. I tested if A == None and if A == "" , but…
-
-3
votes2
answers50
viewsError in Python method call (list)
Good afternoon! I am receiving an error name 'Month' is not defined because of the last method of this code: self.calc_months(month_of_year) def year(self, execution_times): return…
-
-3
votes1
answer1220
viewsFloat rounding up in python 3
How do I round up python 3 ? For example, the 4000/18 calculation always results in 223.
-
-3
votes2
answers621
viewsRemoving unnecessary question mark from a String
I have possible strings, where I would like to have a way to prevent unnecessary question marks and add if missing. However this function applies only at the end of the string. Follow the list below…
-
-3
votes2
answers214
viewsHow to create all possible combinations from a string?
I tried to use a = 'abcdefghijklmnopqrstuvwxyz' itertools.product(a, repeat=4) to create all possible words with 4 letters, but it seems to me that when the quantity is too large it doesn’t work…
-
-3
votes1
answer169
viewsHow to build a basic parse to treat a sentence and extract an action contained in it that will be executed?
I’m trying to put together a simple parse to parse commands entered by a user for a type game Text Adventure. However, I’ve never had experience with it and I don’t know if the structure and types…
-
-3
votes1
answer902
viewsPattern Recognition in Python
Good morning, everyone I am developing a work for college in which I need to recognize images with Python, but the teacher wishes that the recognition algorithm does not belong to a bookstore…
-
-3
votes2
answers129
viewsRead an integer greater than 0 and return the sum between the numbers that compose it in Python
Could someone give me a light on how to make a code, in Python, that reads an integer number greater than 0 typed by the user and add the numbers that make up it? Ex: User type 129 Program returns…
-
-3
votes2
answers1928
viewsAdd values in a list
In python, when printing a certain variable (after a loop) I get as a result: [3] [7] [13] [4] values are within a variable a . Hence when I make list.append(a) and print, I have: [3] [3,7] [3,7,13]…
-
-3
votes1
answer691
viewsWhile listed in python
Could someone help with the following doubt? in "item", the goal is to loop from 0 to 50 id_rec = [conteudo['complainResult']['complains']['data'][item]['id']] I made the following code: item = 0…
-
-3
votes1
answer969
viewsConcept of Simple Circular List
I wanted to know how this process works that the next pointer of the last element points to the first element of the list?…
pythonasked 5 years, 5 months ago user141036 -
-3
votes1
answer65
viewsPlace the information contained in Linha2[0:6] in a ". txt file
Place in a file ". txt" the information contained in Linha2[0:6] which is: ['Mem ria', 'f¡sica', 'total:', '7.988', 'MB'] ['Memria', 'f¡sica', 'available', '5.277', 'MB''] ['Mem ria', 'Virtual:',…
-
-3
votes1
answer108
viewsSyntax error in print
code: # -*- coding: utf-8 -*- import MySQLdb db = MySQLdb.connect(host="xxx.xxx.x.xx", user="xxxxx", passwd="xxxxxxxx", db="xxxxxxx") cursor = db.cursor() cursor.execute("SELECT Dias, HoraConsulta,…
-
-3
votes2
answers65
viewsSyntax invalidates 2 degree equation
The error is in the last Else and I can’t identify, I know it’s a basic mistake. follows below the code: A = float(input("Qual o valor de A: ")) if A == 0: print("Sua equação não é do 2 grau") else:…
-
-3
votes1
answer470
viewsPython pile
I am unable to solve an exercise using python stack... A sequence of parentheses "(" ")", brackets "[" "]" and keys "{" "}" is said to be balanced if each "open" symbol is "closed" at an appropriate…
-
-3
votes1
answer207
viewsTo sort the list of tuples in python by value
To sort a list of tuples by value. For example: x=[{"nome":1},{"data":4},{"dia":5}] I’d like you to stay: x=[{"dia":5},{"data":4},{"nome":1}]…
-
-3
votes2
answers1918
viewsWhat is the best database for Python 3?
I am a beginner and in the future I intend to make a management system for small businesses. A local system, which would be the best database learn to do this kind of software in Python 3?
-
-3
votes1
answer149
viewsPycharm complaining about the local variable
Next, I have a code made in Python 3.7.2 very simple and basic (I’m still learning and wanted to train a little doing a gym training routine). The program works normally, but Pycharm is complaining…
-
-3
votes1
answer122
viewsError: invalid syntax python
Good evening Personal am beginner in Python.Ai when the code appears the if ano=0: Syntaxerror: invalid syntax import requests from bs4 import BeautifulSoup t=input('Digite o Nome do Filme:')…
pythonasked 5 years ago Jacksuel Soares Braga 1 -
-3
votes1
answer72
viewsmy code does not work python
for i in x: print("Jogador 1, selecione a linha para ataque: ") LinhaAtaque1 = int(input("Linha do ataque: ")) print ("Jogador 1, selecione a coluna para ataque: ") ColunaAtaque1…
-
-3
votes1
answer276
viewsPython - Tkinter Grid
How can I build this layout using Grid? The gray rectangle used place, however, I would like to know how to get the same result using Grid in all elements. from tkinter import * class Main(): def…
-
-3
votes1
answer379
viewsHow to know the primitive type of a variable in python
(I am inciante) I have the following dictionary: ''' d = {'nome': ' ', 'Idade': 0, 'carteira de trabalho': 0, 'ano de contrato': 0, 'salário': 0.0} ''' This is the initial version of it, and I have…
-
-3
votes1
answer49
viewsHow does this function work?
That role was in my python test in college and I can’t understand it, more specifically the part of for. def exerc4(a,b,c,d,e,f): if(a > b): x = a + b elif (e > f): x= e + f else: x = a + b +…
-
-3
votes2
answers107
viewsconvert strings to python
I am having doubts to resolve this exercise. First, follow example of txt file. 5/2 500+20 200-20 20*10 I need to read this txt file and solve the equations in Python. Follow the code I currently…
-
-3
votes1
answer602
viewsHow to sort a column in the pivot_table Pandas
Here’s the thing, I need to sort a pivot table to show me the values from highest to lowest. impute_grps = df.pivot_table(values=["winPlacePerc"], index=["matchType"], aggfunc=np.count_nonzero)…
-
-3
votes1
answer49
viewsHow to organize the output that Python returns in the Pymongo module?
I am trying to return database and more functions. Ex: mongodb = MongoClient(args.ip, int(porta)) database = mongodb.list_database_names() print (database) But when the answer comes back, it comes…
-
-3
votes1
answer76
viewsam I new to the programming will you help me?
would like the result of Ifs to enter directly into the variable (Lista2) and to be printed all example numbers [1,3,2,5,5,7,8]. My code so far: lista = [] lista2 = [] while len(lista)+1 <= 7:…
-
-3
votes1
answer486
viewsHow to speed up my python program?
I made a web scraping program, however the requests are very slow, I modified my program in a way that if I run it in several windows it works faster, only it becomes a mess. Is there any way to do…
-
-3
votes2
answers85
viewsI am learning Python and have an exercise using the FOR that I am not able to do, can anyone help me?
Build an algorithm that reads the age and sex of 5 people, providing: *The number of men and women; *The average age of men and women; *The greatest age among men; *The lowest age among women. This…
-
-3
votes1
answer164
viewsPython Recursiveness - Rest of the division of two numbers
I’m having trouble solving a problem in Python using recursive form: Make a recursive function that gets the rest of the split between two positive integers. Example: rest(33,5) = 3 Can you please…
-
-3
votes1
answer203
viewsHow to name the indexes of an array of arrays according to another array?
Having the following array of arrays array1=[indice1[1,2,3], indice2[4,5,6]] and the second array2=['nome1','nome2'] How to make the first array (array of arrays = array1) have the same names in its…
-
-3
votes2
answers53
viewsPrinting lists
Could someone explain why the list of the following code is not printed? Thanks! def produtos_pedidos(produtos): lista = [] while True: pedido = input("Qual produto você quer pedir? Para encerrar o…
-
-3
votes2
answers126
viewsHow to operate on the counter of a while in each loop iteration
Sorry my ignorance I’m starting to learn python now, my doubt is: How can I generate a result in each iteration of a while. valor= input('digite o numero desejado:') contador = 0 while contador…
-
-3
votes1
answer35
viewsHow do I read multiple files and save them?
lista = glob.glob('/content/drive/My Drive/LOCAIS/*.xlsx') lista df = [pd.read_excel(file) for file in lista] df #melhorar dados =…
-
-3
votes1
answer100
viewsUpdate lines in ods file using python
I am looking for a way to update some lines of an existing pre file in ods format using the python language. I managed to create a new file using the code block below, but the need would be to…
-
-3
votes1
answer62
viewsHi, I’m new to Python, and I’m having trouble with a Syntaxerror on an Else
It appears to be written in the right way, but is still making a mistake. No matter what I do the error continues, I have already tried to exchange for an Elif, for an if, but nothing right. Always…
-
-3
votes1
answer2212
viewsUnicodedecodeerror: 'utf-8' codec can’t Decode byte 0xd0 in position 0
line 1383, in <module> print(f.readline()) File "/usr/lib/python3.8/codecs.py", line 322, in decode (result, consumed) = self._buffer_decode(data, self.errors,…
-
-3
votes1
answer52
viewsExtract multiple values from a variable
I’m picking up information from a site where the number of the div changes, have some way to get tried all the numbers up to a limit or need to type them manually ? try: x = 1…
pythonasked 4 years, 5 months ago Rodrigo ZOZ 1 -
-3
votes2
answers126
viewsGenerate executable with more than one file . py
Good evening guys. I did a little project in Python and I’m trying to generate the executable. However, I can’t find any tutorial to teach you how to do this with more than one file. In the case of…
-
-3
votes1
answer246
viewsI’m having a bug with a bot to do operations on IQ Option
He can sometimes make the entrees, but always at the end of that mistake, and I don’t know how to fix Erro: Traceback (most recent call last): File "main.py", line 267, in <module> par =…
-
-3
votes4
answers573
viewshow to create a list of multiples of numbers of 3, from another list of numbers?
meus_numeros = [1, 56, 342, 12, 781, 23, 43, 45, 123, 567] for c in meus_numeros: if c%3 == 0: print(c, end='') File "<ipython-input-12-2b3fd4ceddad>",…
-
-3
votes1
answer47
viewsHow to delete an element in python
I have a database. created a variable and assigns values from a column to it x1 = dataobitos.SEXO there are three distinct values: "F", "M", "Undefined". I need to eliminate "Indefinite," but I…
-
-3
votes2
answers95
viewsHow to store value in a variable and return its primitive type and other information
I need to make a program that reads something on the keyboard and shows on the screen its primitive type and all possible information about it. I’m still developing the code. But I’ve already…