I’m looking for a function like range except that the step is a fraction of the previous number generated. So if the fraction was 99/100 the set of numbers might be something like this: 100, 99, 98.01… 0.001 Would this be more efficiently done with a for-loop and range-like function or with just a while-loop? The code I have so
Tag: for-loop
Is there a way to make “print(l for l in List)” work?
Hi I am trying to shorten my code with some for loops inside of print functions, but I run into this problem: Output: is there a way to make this work without doing: Output: or do I have to stick with that? I am sorry if this question is somewhere else, I just couldn’t find it. If you manage to
Python – Write array output in .csv file for each for loop iteration
I’m trying to write the output data of this for loop in a .csv file. However, what gets written in the .csv file with the current code is the data of a single iteration. I want to append and write the data in a new row for each iteration. How do I do that? Answer Try to append instead of
Dictionary of Words as keys and the Sentences it appears in as values
I have a text which I split into a list of unique words using set. I also have split the text into a list of sentences. I then split that list of sentences into a list of lists (of the words in each sentence / maybe I don’t need to do the last part) I want to write a loop
For loop to get prime numbers [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 1 year ago. Improve this question
iterate through a tuple to form a string
I am trying to create a function named make_string, that uses * correctly with a parameter: strings The function should return a string of all the values supplied joined, and separated by a space. Outside the make_string function, I declare a variable named my_string, and assign the value returned from the make_string function. Then I call the make_string function with
How to use while loop to check difference between calculation output , convergence calculation
I am writing a code that carry outs the calculation: I want to pass incremental n_value value starting from 2 then +0.10 each time it iterates. For the iteration I am writing while loop counter however, codes does not work. However the code does not iterate and I am kind of struggling how to create the iterative loop. I want
Python some for loops one action
I have three for loops with one action. How to merge this loops in one? tried: but this trick working only with ‘if’ loops Answer I’d suggest itertools.chain
Nested FOR loops – coding challenge
I am learning python using STEPIK and I am facing this: I want on every iteration of the inside for loop sum the values of predicted_growth list with the value of cases list, save it in some temporary variable and print it. Click on the link for the full challenge. This is my code so far: This is the output
Perform a list comprehension inside of a for loop in Python [closed]
Closed. This question needs debugging details. It is not currently accepting answers. Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question. Closed 1 year ago. Improve this question In short what I need is to get for each element from this