Questions tagged as 'python'

2
answers

What's the difference between using return and print in this recursive function that calculates the sum of numbers?

I did a simple function in Python to give me the sum of the numbers from n to 0: def retorna(n, zero, soma): if n <= zero: soma += n return soma retorna(n+1, zero, soma) ret = retorna(1, 5, 0) print(ret) The r...
asked by 08.09.2018 / 15:27
1
answer

Message in "print" is not printed on the screen, how to correct? [closed]

The print message does not appear on the screen, does it relate to the variable? cp = str input("seu nome") if(cp)=='jefferson': print('JFP')     
asked by 02.11.2018 / 18:34
2
answers

Convert search with PyMongo: Dictionary in JSON

I'm using PyMongo to do a search: resultado = db.find_one({'nome':'xpto'}) The result of this search is a dictionary in Python, but I need to convert it to a JSON. What is the best way to do it?     
asked by 04.12.2014 / 18:21
2
answers

How to sum the main diagonal of a matrix in python? [closed]

I am developing an algorithm and want to know if there is any command to sum the main diagonal of an array in Python     
asked by 31.10.2018 / 17:59
1
answer

Determine recursive derivative calculation in Python

I need to create an algorithm to determine in N times the derivative of an X function. However, I still have some problems to implement recursive functions, I still can not understand logic. To determine the derivative of the function I'm...
asked by 26.11.2018 / 18:37
2
answers

How do I calculate the average runtime of a function?

To calculate the runtime of a function I'm using inicio=time.time() # código fim=time.time() How do I calculate time repeatedly and then calculate the average of that time?     
asked by 26.11.2018 / 22:55
2
answers

Handling items during iteration

In Python it is somewhat common to go through items from an iterable handle or checking for the existence of a particular item, or whatever the operation. I'm reading the Python documentation again and I come across something that when seen fo...
asked by 20.11.2018 / 23:47
1
answer

Python - Type function in tuples

Hello, I'm trying to make a program in Python, which gets a positive integer. This program should check whether it is integer ( with type ) and whether it is positive . You should return a tuple of integers containing the digits of that nu...
asked by 12.05.2018 / 17:53
1
answer

Subtleties between Python and C [closed]

Good evening! Sunday I discovered that I will have to learn python, that the subject that I will study will be in this language and can not escape. I studied well this week and managed to get to matrices, but I came across subtleties that I'm st...
asked by 10.08.2017 / 03:25
2
answers

How to put more than one parameter in Python?

I'm learning Python3 and I'm having trouble making a Python implementation. For example, in C: for (fatorial = numero; fatorial >= 1; fatorial--) I want to put this above implementation in python: I already did this: for (fatorial...
asked by 23.08.2017 / 01:00