I am trying to create a generator function to return the content of a .csv file row by row and while the generator function does seem to be iterable with me being able to loop over it with a for loop, when I print the object type of the generator function, instead of returning class ‘generator’, it returns class ‘function’.
Tag: function
Novice Python User having issues with simple functions
I am trying to make a simple python program that takes 3 inputs Number of stocks I will Buy Price per share of stock when bought Price per share of stock when sold. In this exercise, there is a 15% commission fee both when buying, and selling the stock. The 4 outputs I am attempting to receive are: Price of
Python: more elegant way to assert type of function input
I am a complete beginner in Python… Currently I am trying to write a function which first checks whether the inputs x and y are int or float. My guess which does the job is if (type(x) != int and type(x) != float) or (type(y) != int and type(y) != float): However, this seems quite clumsy / inefficient to me
The gradient (2d) search function returns None. What is the problem?
I have a function that should return a gradient. But when calculating the gradient at a specific point, I get None. Object classes: t1-function, t2-function, t3-None (I want to get a two-dimensional point) Please tell me how to change this line to make it work? PS. I understand that there are built-in methods for calculating the gradient. But this is
Using the output of a function as an input of another function
Suppose i have function like this. So is it possible for me to use the variable C outside in another function like this? Is this a correct way? Answer just use the returned value as a parameter heres an example: heres how it could apply to your case: first off you’re only going to get one value from this since
‘BACKTICK_QUOTED_STRING__AT_key’ is not defined for Pandas Querying function
Trying to get a hold of pd.query function Getting an error UndefinedVariableError: name ‘BACKTICK_QUOTED_STRING__AT_key’ is not defined for the below pandas Python code. What did I do wrong? Answer Try this : or
Python 3: Calculating percentage change with n number of values
I have a function which should calculate percentage increase / decrease between two values. The parameters in the function are original_value and new_value. Problem: I need the program to take n number of values, for example, six values, and then run the function on every pair of values. An example: The values are 1, 2, 3, 4, 5 and 6.
Python – How to create a delete function for user input?
I’ve been trying to create a program which allows users to view a text file’s contents and delete some or all of a single entry block. An example of the text’s file contents can be seen below: As such, the entry block refers to all lines without a horizontal space. Currently, my progress is at: The delete_function() is meant to
Counting the number of triplets forming GP series in python
The problem statement is: You are given an array and you need to find number of triplets of indices(i,j,k) such that the elements at those indices are in geometric progression for a given common ratio, r and i<j<k. For example, arr=[1,4,16,64]. If r=4, we have [1,4,16] and [4,16,64] at indices (0,1,2) and (1,2,3). I have a solution but I am
Call many python functions from a module by looping through a list of function names and making them variables
I have three similar functions in tld_list.py. I am working out of mainBase.py file. I am trying to create a variable string which will call the appropriate function by looping through the list of all functions. My code reads from a list of function names, iterates through the list and running the function on each iteration. Each function returns 10