Questions tagged as 'python'

1
answer

Limit Input of Python 3 numbers

Using the following code I want to limit from 0 to 2000 the number that can be reported by num import collections num = int(input('Digite um número inteiro: ')) #Inputar número inteiro binario = bin(num)[2:] #Cortar o 0b sequence = bi...
asked by 13.12.2018 / 15:23
1
answer

Encode problem in Python

At some point in my code I get a% var of% of type str containing% with of%. while doing var2 = var.encode() print(var2) is printed var The original word would be 'SENTENCE' When doing SENTEN\u00c7A returns me b'SEN...
asked by 18.12.2018 / 19:04
2
answers

How to fix the Requests encoding in Python?

I'm studying Requests in Python and I'm trying to get the data from the zip code: link p> I can get it, but when it comes to showing them, since I live in São Paulo because of the encoding I get: S\u00e3o Paulo Reading the request...
asked by 17.04.2017 / 02:15
3
answers

How to validate and calculate the control digit of a CPF

How does the algorithm that calculates the digit of a CPF (Brazilian Physical Register) work? And how is this calculation used to validate the CPF? If possible, I would like examples in Python.     
asked by 19.05.2015 / 01:57
1
answer

Calculate pi with python and use of recursion

Calculate pi by the formula pi=(s*32)**(1/3) , being s=(1/1^3)-(1/3^3)+(1/5^3) ... Quantity of s determined by the user. Must be developed in python using recursion. I can not get the expected result, they can help me find...
asked by 01.09.2018 / 16:51
2
answers

Guidelines for using object orientation or procedural in Python and PHP

I am studying PHP and Python and I am feeling a huge difficulty, not in relation to concepts, after all they are independent of language, what is making the study hard is how PHP implements the manipulation of its objects, follows an example :...
asked by 27.08.2018 / 20:45
2
answers

Imports in file __init__.py

I am studying the documentation of Django and I noticed that in some __init__.py files there are imports, I know that the __init__.py file defines a module but I do not understand why it imports.     
asked by 09.08.2018 / 20:26
2
answers

How to make a class inside another inherit a variable instantiated from the latter in python?

See the following python script: class a: def __init__(self,n): self.n=n class b: def __init__(self): ## o que botar aqui para receber a variável self.n ##...
asked by 24.01.2017 / 20:37
1
answer

Good test practice in python

I'm working on a python test for a week, I started with unittest and some doubts came up ... Should I use a test class for each method of a class, or use a test class for each class ... and still, how to proceed with functions that do not belong...
asked by 09.07.2018 / 00:27
2
answers

How do you know how many numbers in a list are repeated in others?

I have four lists with their values: A = [1,2,3,4,5,6,7,8,9,10] B = [1,2,3] C = [4,5,6] D = [7,8,9,10] Would you have some function to compare list A with the other three lists and say how many numbers from list A repeat with those fro...
asked by 19.06.2018 / 02:16