Questions tagged as 'python'

2
answers

How to implement a recursive MDC calculation algorithm in Python?

The non-recursive version is below: def mdc(a,b): while b !=0: resto = a % b a = b b = resto return a print(mdc(50,2)) A recursive attempt would be: def mdc(a, b): if b == 0: return a rest...
asked by 19.04.2018 / 15:23
2
answers

How do I delete empty lists in my list of lists?

I have the following txt file: 1 2 3 4 5 6 7 8 9 2 3 4 5 6 7 6 8 9 3 4 5 6 7 7 8 8 9 1 2 3 4 5 6 7 8 9 4 5 6 7 8 9 10 11 5 6 7 6 7 8 8 9 15 When I open it and generate a list of lists many positions are empty, to try to solve this prob...
asked by 25.08.2018 / 05:31
3
answers

How is the project structure in python?

I would like to know if there is a standard or good practice in how to structure a project in Python. For example, I'm going to do a CRUD using MVC. Something very simple. In JAVA I would create a model folder, a controller and a view. In...
asked by 22.06.2017 / 19:26
4
answers

Calculate sum of digits of a number

Write a program that receives an integer in the input, computes and prints the sum of the digits of this number in the output. Example: >>> Digite um número inteiro: 123 6 Tip: To separate the digits, remember: the // operat...
asked by 31.03.2017 / 03:33
2
answers

string formatting

I have the following string: JOSÉ CARLOS ALMEIDA (0-2) 1 I need to remove the text and spaces and leave (0-2) 1 This way I can deal with trim , split etc ... But my string will not always be the same as the times...
asked by 13.03.2017 / 18:37
1
answer

Why does the '-1' have to be placed right after a variable?

Note: the code is from a book that teaches programming Code: def transação_salva(preço, cartão_de_crédito, descrição): arquivo = open("transactions.txt", "a") arquivo.write(" %s %16.2f \n %s %16s \n %s %17s \n ------ \n" % ("Preço:"...
asked by 17.02.2017 / 01:10
3
answers

Reverse method returns None

I'm applying the reverse method to a list and it returns None . Ex. teste = ['audi', 'subaru', 'fiat', 'ford'] print(teste.reverse())    None     
asked by 12.09.2018 / 03:10
2
answers

How do I find out the name of a button by source code?

I'm working with a library python call splinter , which simulates a web browser. I've read about how to use it, and to click a button, just give a command that involves the name of the button. However, unlike other sites, I can not figure out...
asked by 13.11.2016 / 01:14
2
answers

Is it possible to open a file with IDLE from the terminal?

IDLE allows you to open a file to write our programs (loading CRTL + N if I'm not mistaken), but due to a problem with Python's IDLE 3.4.1 or 3.4.0, I can not use it, it correctly. I can use Python only through the terminal. Is it possible to...
asked by 21.09.2014 / 21:56
2
answers

Is there a method in Python similar to x.find (string), but does it return all occurrences?

For example, I have a string with multiple occurrences of a : a = 'abcdefhanmakaoa' If I use the find method, I can only find the index of the first occurrence. Is there a native method / function that returns all occurrences?...
asked by 02.12.2018 / 13:44