There is 5 fundraising projects, and the purpose of this program is to substract the amount of money that each of n donators will donate from the desired sum of each project The program partially work, but sometimes python typing “TypeError: ‘NoneType’ object is not subscriptable” and the programm fall What can cause this crash? Thank you for your help!
Tag: for-loop
Function that removes duplicates in a list of values assigned to each key in a dictionary?
I want to make a function that first merges the duplicate entries by key in a dictionary, then removes the duplicate values in each key. However, I want the removed duplicates to be relative to the other values in the value list they’re in, not the value lists of the entire dictionary. If possible, could this be done using only
How to Repeat an Iteration in a For loop, Python 3
I am currently working on implementing the numerical method RKF45 (Runge-Kutta-Fehlberg-45) with adaptive step size into python 3 and I believe I am running into a fundamental loop issue that I cannot resolve. Note, the portion of this numerical method I am having trouble implementing is the adaptive step size. I understand the basic algorithm for how this may be
Looping through Pandas Dataframe Columns to count values
I have a column with 14000+ rows and there is only two numbers in this column. When I try this I get an equal 12/12 return for each counter. That is definitely not correct. How do I loop through and count the Yes and Nos? Answer You can do it like this :
Updating a variable inside the for loop is not working
in this below code, I am trying to update rsum value to (rsum – lsum – nums[i]) inside for loop, it’s giving me the wrong output. But if I declare a new variable name and assign (rsum – lsum – nums[i]) value to that, it gives me the right output. What’s the reason behind this? Code that gives wrong output
Iteratively apply a function to an array
I want to create an array that contains g^0, g^1, g^2…. up to g^100 but all to mod50 (apologies if anyone knows how to format this so the powers are properly aligned I need a bit of help!) In my case g = 23, so I would want an array that looks like: I’ve included all my (incorrect) code at
How to write a for-loop/if-statement for a dataframe (integer) column
I have a dataframe with a column of integers that symbolise birthyears. Each row has 20xx or 19xx in it but some rows have only the xx part. What I wanna do is add 19 in front of those numbers with only 2 “elemets” if the integer is bigger than 22(starting from 0), or/and add 20 infront of those that
Subtracting the values in another DataFrame from every column in a pandas DataFrame
I have two DataFrames of 20 rows and 4 columns. The names and value types of the columns are the same. One of the columns is the title, the other 3 are values. Now I would like to create 3 separate tables/lists subtracting each value of df1.col1 – df2.col1 | df1.col2 – df2.col2 | df1.col3 – df2.col3. For df1.col1 –
Python: Image face detection and sorting into face and no face
I am trying to create a sorting system where an image is sorted based on having a face or not. and it doesn’t seem to run quite as expected. after the first image is sorted, the loop stops working and I can’t seem to figure out what is wrong. (I am aware of how inefficient it is). all in all,
Why my for loop is not iterating all the values
When I run this code and give input as 25 it should return me its not a prime num, But when I debug the code the range values are not iterating into if condition, only the first value of the range is passed and if its not == 0 it moves to the else part. Please help me why its