I am trying to solve a problem from a python textbook: Write a program that asks the user to enter the number of times that they have run around a racetrack, and then uses a loop to prompt them to enter the lap time for each of their laps. When the loop finishes, the program should display the time of
Tag: loops
Script freezes after completing a ‘while’ loop in a ‘while’ loop (oops)
How can get the RGB values of every pixel in an image and after it gets all the values of the first row? Script: Answer The way you initialize your x and y values is the problem. X should be initialized back to zero immediately before the second while loop, so that the count starts again for the width of
How do I get the face_recognition encoding from many images in a directory and store them in a CSV File?
This is the code I have and it works for single images: Loading images and apply the encoding Face encodings are stored in the first array, after column_stack we have to resize Convert array to pandas dataframe and write to csv How do I loop over the images in ‘Folder’ and extract the encoding into a csv file? I have
For loop in Python make issue [closed]
Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 2 years ago. Improve this question so earlier I am learning c/c++ and use for loops intensively but now I am learning python and I came
Trying to understand Python loop using underscore and input
One more tip – if anyone is learning Python on HackerRank, knowing this is critical for starting out. I’m trying to understand this code: Output: I put 2 as the first raw input. How does the function know that I’m only looping twice? This is throwing me off because it isn’t the typical…for i in xrange(0,2) structure. At first my
Changing the value of range during iteration in Python
Above the is the code which prints numbers from 0-7 if I use just print i in the for loop. I want to understand the above code how it is working, and is there any way we can update the value of variable used in range(variable) so it iterates differently. Also why it always iterates up to the initial k
Iterating over two lists one after another
I have two lists list1 and list2 of numbers, and I want to iterate over them with the same instructions. Like this: But that feels redundant. I know I can write for item in list1 + list2:, but it has a price of running-time. Is there a way do that without loose time? Answer This can be done with itertools.chain:
How do I reverse a list using while loop?
Input list: [1, 2, 3, 4, 5] Output: [5, 4, 3, 2, 1] I know how to do it with for loop, but my assignment is to do it with while loop; which I have no idea to do. Here is the code I have so far: Answer I would say to make the while loop act like a for
Program to find the nth prime number
I wrote a code in python to find the nth prime number. The code looked fine to me, but it returns an error when I run it: It appears to me as if it is trying to say that I am referring to ptrue in the last line even though I am not. What is the problem here… Can anyone
elegant way of convert a numpy array containing datetime.timedelta into seconds in python 2.7
I have a numpy array called dt. Each element is of type datetime.timedelta. For example: how can I convert dt into the array dt_sec which contains only seconds without looping? my current solution (which works, but I don’t like it) is: I tried to use dt.total_seconds() but of course it didn’t work. any idea on how to avoid this loop?