Questions tagged as 'python'

2
answers

Problem when calculating percentage (result is always "0")

I finished a program in Python (improved with a response obtained right here in Stack Overflow), but I'm trying to include a percentage calculation that is not working. Although everything else works, the result of the percentage is always "0"....
asked by 10.01.2018 / 03:03
1
answer

How to find specific words in a txt file in python?

I need to make software that looks for words in the code and saves the next line in a string. I did not find anything how to do this anywhere, I just found one that counts the number of words in the file like this with open('File_of_data.txt',...
asked by 14.10.2017 / 04:39
1
answer

python I can not use the break

This is a game that simulates a race. However, when a player reaches level 3 I want to stop the loop and clear all data, but I can not use break so that when the level of one of the players is 3, game and finish. import random class J...
asked by 16.11.2017 / 11:32
1
answer

Is it possible to collect an html source code using python?

I would like something in python, some library that could access the site and get its source code (HTML). Example: Talsite.com <h1>hello</h1> Is it possible for python to get into Talsite.com and collect the source code for it?...
asked by 12.11.2017 / 14:56
2
answers

How to find the key name in a dictionary by the value contained in it?

Here's an example. dicio = {'pizza': {'massa', 'ketchup'}, 'feijoada': {'feijão', 'linguiça'}} user_input = 'feijão', 'linguiça' #Input How to check if this input is in the values of this list and if it is how can I get the name of the key...
asked by 11.11.2017 / 20:42
1
answer

How to only allow the creation of valid objects in Python?

class Linha(object): def __init__(self, x, y): self.x = x self.y = y @property def x(self): return self._x @x.setter def x(self, valor): if valor >= 0: self._x = valor @proper...
asked by 12.11.2017 / 05:19
1
answer

count how many times the loaded word from the txt file appears python [closed]

I need to make a program where I save a txt file, then open it and read it. So far so good. But I do not know how to show how many times each word of the open text appears. Ex: The text appears the word mil 5 times, the word house 7 times and...
asked by 07.10.2017 / 14:15
2
answers

Separate each word of the sentence into an index of the list in python

This code snippet generates the following output. tamanho = len(lista_nome_base_docs) print (tamanho) lista_geral_de_lista_arquivos = [] for i in range(tamanho): with open(lista_nome_base_docs[i],"r") as arquivo: conteudo = arquivo.readl...
asked by 06.10.2017 / 19:19
1
answer

Manipulate text files in python

I know I can not write to a file that I open in read mode, but I wanted to know if I can read the lines of a file that I open to writing, after writing it ?     
asked by 09.10.2017 / 15:04
1
answer

Return from file reading function in python

I made this code snippet to loop through the contents of the list files. lista_nome_base_docs = ['a.txt', 'b.txt', 'c.txt'] tamanho = len(lista_nome_base_docs) print (tamanho) lista_geral_arquivos = [] for i in range(tamanho): with ope...
asked by 06.10.2017 / 15:53