In Python I have a list of entries. I need to get the sum of expenses, the sum of income, and the profit. I’ve been able to get the expenses and income. Looking to break out the profit. I know I’m missing something simple but can’t figure it out. Answer Looks like you just want to calculate the profit/expenses/income for
Tag: loops
How can i print the specific line number of a json file
I am using python to load a json file and using jsonschema to print errors according to the schema i have prepared. My question is how do i print a specific line of a json file from a loop: The output i get is ‘lending_details’ is a required property which is the error.message. What i want is to print: On
Python iterate folder of csv and convert do json
I am amateur at python but I have a task of converting folder of csv to json files. I have this script working with specified CSV file but I have no idea how to make the script iterate thrue folder of csv and convert all of those csv to json. The original script: someone will give me a hint? Answer
Why is the printing order reversed in a simple loop built inside a function(Python) [closed]
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers. This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers. Closed 9 months ago. Improve this question
How to save each line of a file to a new file (every line a new file) and do that for multiple original files
I have 5 files from which i want to take each line (24 lines in total) and save it to a new file. I managed to find a code which will do that but they way it is, every time i have to manually change the number of the appropriate original file and of the file i want to save
for loop with zip in python
I want to use zip to iterate to existing Lists. I did that with the code below. Currently the output is just Name –> Name. How do I use the new creates list or if that’s not possible the other lists to print following sentence: “#NAME is #AGE years old, and they can be called at #NUMBER”. Is it possible
Iterating through a column and mapping values
Here is what I am trying to do. I want to substitute the values of this data frame. For example. Bernard to be substituted as 1, and then Drake as 2 and so on and so forth. How to iterate through the column to write a function that can do the following. Answer The function already exists – pd.factorize. It
Output variable names when summing a tuple
A list of variables with assigned values. I want to return all the possible combinations from each pair (every two of them). The print-out is the names of the pair, and sum of them. For example: I’ve tried below. The result comes out, but not the names of pairs: What’s the right way to do it? Answer If you use
How can I create a loop with my conditions
i am looking for help. We need to write a program that prints all numbers in the range of (n -20,n + 20). In addition, the program asks you beforehand to input a number. If that number is not even or multiple of 10, you need to take a guess again. Only if the number is even and multiple by
why does nested loop start from 0 and how to change it to start from where it had left?
I want to generate a code that will write 20 rows from each of two different dataframes. Therefore, I created something like below. Everything works fine except nested loop (u) starts from 0 each time. Can you help me how to fix it to start from where it left, please? Answer Do you want to alternate between the two tables?