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
-
-2
votes1
answer66
viewsFix infinite loop
Hello, I made a code for a function that loops infinity every time I call but I can’t figure out why. Follows the code: def geraprimos(qtd, inicio, fim): lista = [] while len(lista) < qtd: numero…
pythonasked 4 years, 3 months ago Yasmin Teixeira 47 -
-2
votes1
answer115
viewsHow to add 2 objects and return number, in Python?
I have the following class: class num(int): def __init__(self, n): self.n = n I would like it to work as follows: A = num(2) B = num(3) A + B = 5 This is part of a much more complex personal…
-
-2
votes1
answer48
viewsBase64 getting corrupted via post in flask
I’m sending a Base64 inside a post to flask, and it’s replacing the "+" plus sign with spaces " ". Example of original code: curl -X POST localhost:5000/api/send -d 'data={"num": "01", "msg":…
-
-2
votes2
answers38
viewsI would like to know how to get the value of the amount of commutations in a list sort. without using Sorted()
s = [2, 4, 3, 1, 6, 7, 5, 8] for i in range(len(s)): for j in range(i+1,len(s)): if s[i] > s[j]: aux = s[i] s[i] = s[j] s[j] = aux …
pythonasked 4 years, 3 months ago Marcio Pedro Dos Santos 1 -
-2
votes2
answers716
viewsAttributeerror: str Object has no attribute 'Confidence'
I’m developing a chatbot and I wish it would only respond if it had determined level of confidence in the answer. # -*- codding: utf-8 -*- import os import telebot from chatterbot import ChatBot…
-
-2
votes1
answer65
viewstwo are in the same row within a list
guys I’m reading the book fluent python And right at the beginning I come across an instruction I’ve never seen before and I can’t find any information about it. The instruction is as follows:…
-
-2
votes3
answers98
viewsHow to identify numeric digits in numbers within a list?
I need some help. I am stuck in an exercise where beyond several guidelines, asks me to remove all numbers within a list that end with 7 (17, 27, 37, etc) How would I do that? (python)
-
-2
votes1
answer128
viewsCalculate pi with the python sequence
A program that calculates X by the series: 4-4/3+4/5-4/7+4/9-4/11... with precision of 10^-4 I have done so, but he lists the term and does not sum. What q is wrong? n = 1 while True: n = n + 1…
-
-2
votes1
answer44
viewsascending order:
Write a program that reads three integers from the keyboard. As output, print the values in ascending order. Well according to the question have to use the functions min(a,b,c) and max(a,b,c).…
pythonasked 4 years, 1 month ago Thiago Zurra 1 -
-2
votes1
answer83
viewsHow to print only vowels contained in a string?
Implement a Python function that takes a string as a parameter and prints the vowels of that string. Example: string univesp must print out the characters 'u', 'i' and 'e'. I managed to do it here,…
pythonasked 4 years, 1 month ago halbuquerque 11 -
-2
votes1
answer73
viewsHow to add lines from one matrix into another?
I have two matrices new_output and new_output_test and would like the matrix data new_output_test were added to the matrix new_output as the last data of this matrix. new_output Out[65]:…
-
-2
votes2
answers243
viewsTransform [hh:mm] into float (ex: 01:30 ==> 1.5) in python
I have a data list in [hh:mm] format and I want to convert it to float. ex: hours 01:00 01:35 00:45 00:20 I would like to transform these varoles in 1.0, 1.5833, 0.75, 0.3333 to achieve 3.67 as an…
pythonasked 4 years, 1 month ago Jose Pedro Guirao 11 -
-2
votes1
answer491
viewsTwo dice game in Python
I couldn’t do a function that simulates a two-dice game and counts how many times the dice were played until repeated numbers come out. def dados(): dado1 = [random.randint(1,6)] dado2 =…
pythonasked 4 years, 1 month ago Marco Raad 43 -
-2
votes1
answer51
viewsremove lists from a dictionary
I have a code that tests several combinations that are generated, but I have a memory error problem. I think the cause of this is that the dictionary gets too big to be processed, so I thought the…
-
-2
votes4
answers87
viewsComparing dictionary values() with list values
I have the following dictionary and a list; from the dictionary I extracted the top 10 values. My question is this: I need to compare the keys of the respective values extracted from the dictMaior…
-
-2
votes1
answer67
viewsCan anyone help me find the bug? python!
in this exercise you need to find the harmonic average but it is giving error (the -1 is to stop the x and the x has to be between 1 and 10 3 and the n is the number of notes.) when it tries to…
-
-2
votes1
answer106
viewsPython - Scan File and Extract Data from Sticky Tags
Good morning, you guys! So, I’m starting in python and I have a question regarding string. I have a file with information and need to extract some data from it and move to another file. Basically, I…
pythonasked 5 years, 4 months ago Douglas Guerreiro 1 -
-2
votes1
answer47
viewsPython Virtualenv showing computer libs
good night. (I use Ubuntu) I’m dealing with flask with some colleagues and we use Virtualenv to create virtual environments. My problem is this: Whenever I pull something from github and already…
-
-2
votes1
answer874
viewsSelect the top 10 values of a dataframe variable in python?
I need to figure out the top 10 values of the variable qty sales together with the information of client name of a sales base. To find out the names of the 10 customers who bought the most. Making…
pythonasked 4 years ago Lucas Marques Vieira 57 -
-2
votes2
answers54
viewsHow to interrupt the algorithm?
I am not able to interrupt the execution of the program, in case the student is approved without recovery. I have tried Return and break, but, it did not work. n1 = int(input('Insira a nota da prova…
-
-2
votes1
answer204
viewsFunction for monthly media calculation
I want to calculate the temperature average of each month of the year using a function. It’s not working. Follow the code I tried import pandas as pd tabela =…
-
-2
votes1
answer234
viewsHow does "parse" work for handling dates in Python?
I’m using a sequence of codes to apply in a forecasting: ''' dataparse = lambda dates: pd.datetime.strptime(dates, '%d/%m/%Y') df = pd.read_csv('BBSE3.csv', encoding ='utf8', sep=';', parse_dates =…
-
-2
votes1
answer54
viewsGet the lowest value with the map in a Dict
I’m studying the function map() And I was wondering if there’s any way I could retrieve the least value from a dictionary within a list. The way I’m doing I’m only managing to change all values.…
-
-2
votes2
answers581
viewsHow to pass python variable to sql query?
I am using Mysql as a database. I wanted to be able to pass the value of a python variable as a parameter in this query. Ex: cursor = connection.cursor() variavel_nome_cliente = input('Digite aqui o…
-
-2
votes1
answer117
viewsDisplay Qtd of read numbers, medium, larger and lower read value
I have the following code: qtdNumeros = int(input()) if qtdNumeros <= 0: menor = "Nenhum" media = "Nenhuma" maior = "Nenhum" else: menor = maior = soma = float(input()) for proximo in range(1,…
-
-2
votes2
answers87
viewsProblem involving classes, vectors and tuples
Hi, I’m a little confused about the concept of lists and tuples in Python. In my research I noticed that tuple is a "kind of immutable list", but, despite the definition, I still can not…
-
-2
votes1
answer103
viewsHow to allow input() to receive scientific notation in python 3?
I have a thermal expansion coefficient that the user must provide, example 1.6*10e-5, exactly this value, how to allow the user to write this value in scientific notation? input of the coefficient…
-
-2
votes1
answer39
viewsHow can I use more than one function in the same Thread?(python)
I already tried that but it says that the is not defined: import threading as te import time b=[] def c(): global a a=0 while b==[]: time.sleep(0.001) a+=0.001 def i(): b.append(input('enter'))…
-
-2
votes1
answer59
viewsserverless deploy command not found even after installation
I installed the serverless via npm, but it says that the serverless and serverless deploy command do not exist, not even serverles -v, as if it had not installed via npm.
-
-2
votes1
answer46
viewsIs it possible to create dictionaries using surreptitious ties?
I was wondering if I could create a dictionary using loops. But I don’t want to create a dictionary within a list [{ }]. example: from random import randint jog = dict() for n in range(1, 5):…
-
-2
votes1
answer119
viewsHow to make an auto sum function in javascript
How can I do a function in javascript that changes the total_productions field every time a field changes its value in the form? I have the following code Template <form class="form" role="form"…
-
-2
votes1
answer32
viewsAutomatically put words in a list
I’m doing a program similar to a dictionary. When making a list to store words have some form of words, automatically get in quotes and have commas? For example, if I take multiple words from a…
-
-2
votes1
answer37
viewsColumn filter and average calculation
good afternoon I am studying a datasets and need to find out the average price of houses with 2 bathrooms? I used the code: print(data["bathrooms","price"]]. groupby("bathrooms"). Mean()) Note: I am…
pythonasked 3 years, 10 months ago Bruno Oliveira 1 -
-2
votes2
answers221
viewsCreating an Entry formatted for CPF in Python (Tkinter)
I would like to know how would be the application of a formatting in a field Entry, using the tkinter, for the format of CPF numbers, in the case of, XXX.XXX.XXX-XX. I found nothing similar, only…
-
-2
votes1
answer85
viewsMy program seems not to be correct, what to improve?
maior50 = menor20 = maior10 = 0 x = 1 while x <= 20: idad = int(input("Digite sua idade:")) alt = float(input("Digite sua altura:")) peso = float(input("Digite seu peso:")) x = x + 1 if idad…
-
-2
votes1
answer92
viewsSum the total values of each key of the Python dictionaries
I have the following list of Python dictionaries : creches = [ { "nome": "Recanto do Sol", "cachorros": 12, "gatos": 4, "coelhos": 2, }, { "nome": "Lar dos bichos", "cachorros": 8, "gatos": 5,…
-
-2
votes1
answer128
viewsHow do I use the Python range function in this specific case?
I have a problem and I’m looking for the best way to solve it. I have a function that inserts in an array 26 positions starting from the letter 'to' down to the last letter of the alphabet which is…
-
-2
votes2
answers137
viewsFunction returning another function
How the second function is returning the function f? And where the function is being returned to f since, when I give print in the variable, the value returned is 'hi' and 'None'? def f(var):…
-
-2
votes1
answer59
viewsHow to enable Virtualenv in Windows command prompt?
On Linux I can run . bin/activate I tried the same command on Windows, but it didn’t work. How do I activate virtualenv on Windows?
-
-2
votes1
answer26
viewsHow can I upload files so they work on other Pcs even if the path to the file is different? (Pygame)
Oops! So... I’m doing a program using the pygame, and when it comes time to upload a file, I should use this, right? bulletImg =…
-
-2
votes1
answer132
viewsClose Tkinter window after few seconds
Whoa, guys, I’m having a very simple doubt. I need to close the Tkinter window after a few seconds automatically, someone can help me? Follows the code: from tkinter import * from PIL import…
-
-2
votes2
answers58
viewsI cannot execute if and Elif commands
I’m taking an IT course and I’m taking my first lessons with Python, I’m using Pycharm but the code I’m doing does not perform the function "if" no matter what I say in response. print("menu") reg=…
-
-2
votes1
answer65
viewsHow do I ignore one in the Python code
.download('C:\Users\Guilherme\Downloads') I used Pytube and to download this folder I need to '', someone knows how I can ignore p work normally?
-
-2
votes1
answer44
viewsHow to generate a user-defined list?
I want to create a list where the user sets the amount of items in the list and asks the user for each item in the list. I did it that way: n = int(input("Digite a quantidade de células da sua…
-
-2
votes1
answer34
viewsHow to "zoom" a file into another file in visual studio code
I am with some projects in python, and to facilitate my work, I do "sub-files", ie, I create other files and "compile" them while running the program by the function: "exec". But I came across a…
-
-2
votes2
answers266
viewsFILL MATRIX WITH PYTHON RANDOM VALUES
I need to create an array of random values, I was thinking of using Random but I’m having difficulty adding this data to the matrix; I’ve already defined that is a 3x3 matrix. Could someone help me,…
pythonasked 3 years, 8 months ago ingred almeida 27 -
-2
votes1
answer38
viewsHow can I remove 'R$ xa0' from a obtained result?
I am collecting data from a particular site, where when collecting some values I am facing some difficulties and would like to help to solve. I have the following code: valores =…
-
-2
votes1
answer41
viewsconnecting AWS RDS postgres with python
I have a database mounting with the postgres engine in the AWS RDS I would like to know how to access it through python import psycopg2 import sys import boto3 ENDPOINT="endpoint na AWS" PORT="5432"…
-
-2
votes1
answer208
viewsHow do I log in automatically through a get, with the Request library in python?
Code: import requests username = 'admin' password = 'admin' headers = {'login': username, 'password': password } url = 'http://192.162.1.122/ISAPI/Event/notification/httpServers/ID' r =…
-
-2
votes1
answer126
viewsHow to replace a comma for an integer df point without having to do column for column - Python
I have the following code: df10['Total_Forecast'] = df10['Total_Forecast'].apply(lambda x: float(x.replace(".","").replace(",","."))) It’s working, but I need to apply replace column by column of…