Questions tagged as 'python'

3
answers

Python - Cycle is an alternative to the while loop

Generic considerations: I am currently programming in python ; I have a relatively simple level code; The code contains an instruction loop of type while loop ; I would like to know if there is a way to run the code specif...
asked by 12.05.2018 / 12:48
1
answer

How to list all files in a folder using Python?

I'm building a program that needs to know the files in the working directory of it. So I typed the following code. def encontrar_arq(cadena, caminho): encontrado = False # lista_arq = ls(caminho) #funcao que lista todos os arquivos do ca...
asked by 19.09.2016 / 05:23
2
answers

Difference between If and Elif

What is the difference between the two code snippets if variavel < 10: variavel = 1 if variavel >= 10 and <15: variavel = 2 . . . else variavel = 0 if variavel < 10: variavel = 1 elif variavel >= 10 and <15:...
asked by 26.11.2016 / 12:01
2
answers

About the structure of the 'sorted' function, how does it work?

The statement below is made as many times as the size of the sub vector. What is the result of this instruction? sorted(sub, key = lambda x : size(x) ) Where x are values from 0 to 31 inclusive and sub is an array of th...
asked by 04.12.2018 / 00:15
2
answers

Ignore if uppercase and lowercase in string

n1 = input('Qual é o seu bolo favorito?') if n1 = 'Bolo de Chocolate': print('teste123') If you write "Chocolate Cake" all in lowercase or all in uppercase, it will end up happening not to enter the if that I created, does anyone kn...
asked by 26.10.2018 / 23:22
1
answer

How does Python determine if a value is true?

I have the following question: >>> a = [200,100] >>> a[True] Output >>> 100 >>> a = [200,100] >>> a[False] Output >>> 200 Why does this happen? Is the first value f...
asked by 21.01.2018 / 19:05
2
answers

How to transform byte integers into the Python language?

I'm using the pyserial module to send serial data, so I have a list of values like: Valores = [10,20,30,40,50,60,70,80,90,100] I need to convert the values of the list into bytes to be able to send, because if I try to send it like this:...
asked by 19.01.2018 / 18:50
3
answers

Instantiating a class in Python using an object as an argument

I'm starting to work with Python and I've seen that there's no way to create multiple con- trollers in the same class. With this I thought of passing to the% co_conductor an object containing the attributes of the class, as in the example: cla...
asked by 06.09.2016 / 16:51
3
answers

Exercise changing last element

exercise:    Write a function that receives a phrase and an old word and a   new word The function should return a string containing the phrase   original, but with the last occurrence of the old word replaced   by the new word. The data inpu...
asked by 08.10.2018 / 14:48
2
answers

Read specific line of a txt file

I have a file of 1000 lines and I want to read line 952. I do not want to have to use a loop to go through all those lines, is there any more optimized way to do this?     
asked by 16.09.2018 / 20:40