Questions tagged as 'python'

3
answers

Identify a numerical sequence in a text file

I'm new to Python, and with a problem I'm not finding a solution to. I have a folder with about 10k of .txt (written in the most varied ways). I need to extract the FIRST sequence of 17 numbers that is located in the first lines of these txt's,...
asked by 16.11.2017 / 12:20
3
answers

Doubt with variables

Hello, I have a question, it seems to be silly but this is disrupting me, I know that in Python it is not necessary to add a type to the variable, example: name = str ("Python") but I see some people declaring the same as above, is there a right...
asked by 09.01.2018 / 19:27
1
answer

Formatting strings with ".format" and "%"

It's been a while since I've been studying some python code that I come across this situation. Some people format the code using ".format": fruta = "Maça" print("Eu gosto de {0}!".format(fruta)) And others use the "%" fruta = "Maça" pr...
asked by 31.07.2017 / 22:08
1
answer

What's wrong with the logic of this'Python 'code?

x = bool(input("True or False...? ")) if x == 'True': print("Você escollheu True") else: print("Você escolheu False") What is wrong with this logic, more specifically about the logic involving the Boolean variable?     
asked by 10.12.2016 / 03:14
1
answer

Error in exception handling (try) in python

I'm doing a program that does numerical calculations, but I constantly see operations where there is division by 0 (zero) . I ended up finding a solution using if , but I still wanted to know why try can not handle this except...
asked by 09.12.2016 / 03:40
2
answers

File txt for list in python

I have several files with shape values: 0.4350 0.8798 0.0099 1 0.4375 0.8674 0.0090 1 0.4400 0.8682 0.0082 1 How do I load these files into Python in the way [[0.4350, 0.8798, 0.0099, 1], [...
asked by 30.04.2017 / 16:35
3
answers

Print "n" natural odd numbers

I am solving an exercise that asks me to enter a value for example: 5 and print the first 5 natural numbers in the case: entry: Type the value of n: 5 1 3 5 7 9 The code I wrote works however does not seem to me the best log...
asked by 11.04.2017 / 05:48
1
answer

How to write in a file without erasing old things?

Example: in my file you have joao maria carla If I use: arq = open('nomes.txt') arq.write('jose') arq.write('\n') arq.close It will delete the previous ones that was joao, maria, how do I write without deleting the previous txt?     
asked by 28.04.2017 / 17:40
1
answer

How to read PDF

I'm creating a script to get a pdf and rewrite it in text. from StringIO import StringIO from slate import PDF from subprocess import Popen, PIPE, call import uuid #pego pdf existente url = "/tmp/arquivo.pdf" with open(url, "r") as arq:...
asked by 27.10.2016 / 22:59
2
answers

How to increment the value of a variable according to the user's response?

I would like to ask the user a question to say "yes" or "no". If the answer is "yes" add 10 pesos to the variable peso and if it is "no", do not add. I'm having a question on how to convert the string to integer. fotossenbilidade =...
asked by 31.01.2018 / 08:45