while-loop

Square number sequence in Python

北战南征 提交于 2021-01-15 10:30:39
问题 I'm new to python and I am trying to make a code to print all the square numbers until the square of the desired value entered by the user. n = raw_input("Enter number") a = 1 while a < n: a = 1 print(a*a) a += 1 if a > n: break When I run this code it infinitely prints "1" ... I'm guessing that the value of a does not increase by += so it's a=1 forever. How do I fix this? 回答1: There are some problems. First, your input (what raw_input() returns) is a string , so you must convert it to

How to control a while loop iteration in a class from a while loop outside it

ε祈祈猫儿з 提交于 2021-01-07 00:38:48
问题 I am trying to read frames of a video leveraging a multithreading class. So, there is a while loop inside the class, which keeps reading the video. And there is a while loop in the main, which accesses the frames from the variables of that class, but what I found is, the outer while has no control over the inner while. It is just grabbing the current running frame from the inner while. To experiment, I put a sleep and saw the loss of frames. I do not want that, I want the outer loop to get

How to control a while loop iteration in a class from a while loop outside it

前提是你 提交于 2021-01-07 00:04:51
问题 I am trying to read frames of a video leveraging a multithreading class. So, there is a while loop inside the class, which keeps reading the video. And there is a while loop in the main, which accesses the frames from the variables of that class, but what I found is, the outer while has no control over the inner while. It is just grabbing the current running frame from the inner while. To experiment, I put a sleep and saw the loss of frames. I do not want that, I want the outer loop to get

How to control a while loop iteration in a class from a while loop outside it

你说的曾经没有我的故事 提交于 2021-01-07 00:03:04
问题 I am trying to read frames of a video leveraging a multithreading class. So, there is a while loop inside the class, which keeps reading the video. And there is a while loop in the main, which accesses the frames from the variables of that class, but what I found is, the outer while has no control over the inner while. It is just grabbing the current running frame from the inner while. To experiment, I put a sleep and saw the loss of frames. I do not want that, I want the outer loop to get

CPU usage increases for Empty Infinite While loop

安稳与你 提交于 2021-01-02 06:20:49
问题 Can anyone explain me why the following Infinite loop takes a lot of CPU usage ( CPU usage has increased upto 50% if total core is 2 and 100% if total CPU core is just 1 ) But if I un-comment the line it reduces to 1 or 2 CPU usage? public class Program { public static void Main(string[] args) { while (true) { //Console.WriteLine("hello.."); } } } 回答1: The reason is because your CPU cannot do anything else while it's executing that loop. The CPU is not aware that the infinite loop isn't a

CPU usage increases for Empty Infinite While loop

五迷三道 提交于 2021-01-02 06:19:21
问题 Can anyone explain me why the following Infinite loop takes a lot of CPU usage ( CPU usage has increased upto 50% if total core is 2 and 100% if total CPU core is just 1 ) But if I un-comment the line it reduces to 1 or 2 CPU usage? public class Program { public static void Main(string[] args) { while (true) { //Console.WriteLine("hello.."); } } } 回答1: The reason is because your CPU cannot do anything else while it's executing that loop. The CPU is not aware that the infinite loop isn't a

Bash while loop wait until task has completed

懵懂的女人 提交于 2021-01-02 05:31:29
问题 I have a bash script that I created to process videos from within a folder and it's subfolders: find . -type f -name '*.mkv' | while read file; do ffmpeg -i $file ... done The problem: Instead of the while loop waiting ffmpeg to complete, it continues iterate through the loop. The end result is, files not getting processed. I need a way to have the current while loop iteration to wait until ffmpeg is complete before continuing to the next. Or alternatively a way to queue these items. Edit: So

Sum list values within a given range using while loop

耗尽温柔 提交于 2021-01-01 20:42:04
问题 I'm trying to sum the values of a list, but only if list values are within a specific range (for example between 5 and -4 , or <= 0 ) Use a while loop to solve this. Don't use additional lists. The code doesn't work if I use is smaller than within the statement to check list values. Where am I going wrong while using "<"? My example data: # list ulis = [ 5 , 4 , 4 , 3 , 1 , -2 , -3 , -5 , -7 , -7 ] #e 0 1 2 3 4 5 6 7 8 9 # list length ulis_l = len (ulis) # to count total total_1 = 0 # index

Sum list values within a given range using while loop

丶灬走出姿态 提交于 2021-01-01 20:26:32
问题 I'm trying to sum the values of a list, but only if list values are within a specific range (for example between 5 and -4 , or <= 0 ) Use a while loop to solve this. Don't use additional lists. The code doesn't work if I use is smaller than within the statement to check list values. Where am I going wrong while using "<"? My example data: # list ulis = [ 5 , 4 , 4 , 3 , 1 , -2 , -3 , -5 , -7 , -7 ] #e 0 1 2 3 4 5 6 7 8 9 # list length ulis_l = len (ulis) # to count total total_1 = 0 # index

Sum list values within a given range using while loop

梦想与她 提交于 2021-01-01 20:26:26
问题 I'm trying to sum the values of a list, but only if list values are within a specific range (for example between 5 and -4 , or <= 0 ) Use a while loop to solve this. Don't use additional lists. The code doesn't work if I use is smaller than within the statement to check list values. Where am I going wrong while using "<"? My example data: # list ulis = [ 5 , 4 , 4 , 3 , 1 , -2 , -3 , -5 , -7 , -7 ] #e 0 1 2 3 4 5 6 7 8 9 # list length ulis_l = len (ulis) # to count total total_1 = 0 # index