Questions tagged as 'python'

1
answer

Difficulties with IF

Good morning, guys. I am still new to programming, I am trying to write a simple program, which calculates the coefficient of performance and report the percentage of the finished course, but I am having problems with an if conditional that is n...
asked by 28.12.2018 / 14:48
1
answer

A function that does the opposite of an addition mod 2³²

def mod_2to32sub1(x): s = 0 # the sum while x > 0: # get the digits s += x & (2**32-1) x >>= 32 if s > 2**32-1: return mod_2to32sub1(s) elif s == 2**32-1: return 0 else:...
asked by 03.12.2018 / 21:33
3
answers

Problem in keeping quotation marks

famous_person = "Dalai Lama disse:\n" message = "\Se quer viver uma vida feliz, amarre-se a uma meta, não a pessoas nem a coisas\" print(famous_person + message) I have tried everything (including putting two quotes). If I put two quotes to...
asked by 16.12.2018 / 13:19
2
answers

Copy the value of a variable type list, to another in python

I am declaring an X variable with the value of another Y using = , but when having a append in the variable X >, Y also changes. Code: ''' Resultado obtido: ['casaRJ', 'casaSP', 'casaDF', 'apRJ', 'apSP']...
asked by 30.12.2018 / 21:20
1
answer

"SyntaxError: invalid syntax" error [closed]

I was trying to run a very simple program through the terminal (use ubuntu gnome): #encoding: utf-8 y = int(input("Ultimo número: ")) x=0 while x <= y if x % 2 == 0 print (x) x=x+1 and I came across the following error: File...
asked by 06.07.2016 / 01:35
2
answers

How to set the largest prime number within a given number?

For example, you give the number 100 and the largest prime number within 100 is 97. How can I program this? "Write the largest_primo function that receives an integer greater than or equal to 2 as a parameter and returns the largest prime num...
asked by 06.04.2017 / 08:28
2
answers

Common elements between lists

How do I compare elements of 2 lists, and return the quantity of elements in common? For example: a=[1, 2, 3, 4, 5] b=[6, 7, 8, 9, 10, 1, 2, 11, 22] This should return 2, because there are only 2 elements in common.     
asked by 22.11.2017 / 18:45
1
answer

after creating a file (.txt) iterate from a line other than the start [closed]

It is the following I have an input file (.txt) which is as follows: 9 branco preto azul verde rosa amarelo vermelho cinza lilas OHLEMREVU BBRANCOZA SRAMSUPAO AABAPOTZZ LNZROERNU IUIEPDOII LOLLORACA ITMOTERPP LIEAZVYUU and from this I want...
asked by 08.01.2017 / 18:24
2
answers

Multiplication of matrices

Could you give a help with Array in python ?! The exercise is as follows, a matriz_mult(n1, n2) function receives two arrays as a parameter and returns True if the arrays are multiplied in the given order and False otherwise...
asked by 01.03.2017 / 20:43
2
answers

How to pass arguments by value in Python?

def somentenumeros(entrada): try: int(entrada) return True except: return False while True: cpf = input('Digite seu CPF ou digite os nove primeiros digitos ') if somentenumeros(cpf) == False or len(cpf)!=...
asked by 04.03.2017 / 12:52