while-loop

Bash break while loop by user input

假装没事ソ 提交于 2019-12-14 02:59:12
问题 I got me a little stopwatch which I put into bashrc with the following code: stopwatch() { date1=`date +%s` echo $1 while true; do echo -ne "$(date -u --date @$((`date +%s` - $date1)) +%H:%M:%S)\r" done } The ouput would look like this while the time would just count up in the second line: ~$ stopwatch test test 00:00:04 Now if I want to end the stopwatch I press Ctrl+C which gives me this: ~$ stopwatch test test ^C:00:03 I'd like to end the loop while containing its ouput using e.g. my enter

Python: Closing a for loop by reading stdout

回眸只為那壹抹淺笑 提交于 2019-12-14 02:43:22
问题 import os dictionaryfile = "/root/john.txt" pgpencryptedfile = "helloworld.txt.gpg" array = open(dictionaryfile).readlines() for x in array: x = x.rstrip('\n') newstring = "echo " + x + " | gpg --passphrase-fd 0 " + pgpencryptedfile os.popen(newstring) I need to create something inside the for loop that will read gpg's output. When gpg outputs this string gpg: WARNING: message was not integrity protected , I need the loop to close and print Success! How can I do this, and what is the

Difference Between Real calculation number and the one i calculate with javascript function

北城余情 提交于 2019-12-14 02:33:44
问题 This is the function that I write for exponentiation like the Math.pow function in JavaScript. Code: function tavan(){ var adad=document.getElementById("pain").value; var tavan=document.getElementById("bala").value; var kol=adad; while((tavan-1)>0) { kol=kol*adad; --tavan; } document.getElementById("main").innerHTML=kol; } After testing this function, everything seems right. Then I test this Phrase 4^28 and the result is 720575940379279**40**. In windows calculator it was 720575940379279**36*

Why while loop is sticking at raw_input? (python)

不羁岁月 提交于 2019-12-14 01:32:33
问题 In the following code i am trying to make a "more" command (unix) using python script by reading the file into a list and printing 10 lines at a time and then asking user do you want to print next 10 lines (Print More..). Problem is that raw_input is asking again and again input if i give 'y' or 'Y' as input and do not continue with the while loop and if i give any other input the while loop brakes. My code may not be best as am learning python. import sys import string lines = open('/Users

python setting limit for running time with while loop

六月ゝ 毕业季﹏ 提交于 2019-12-14 00:40:59
问题 I have some questions related to setting the maximum running time in python. In fact, I would like to use pdfminer to convert the pdf files to .txt. The problem is that very often, some files are not possible to decode and take extremely long time. So I want to set time.time() to limit the conversion time for each file to 20 seconds. In addition, I run under windows so I cannot use signal function. I succeeded in running the conversion code with pdfminer.convert_pdf_to_txt() (in my code it is

Display running total

可紊 提交于 2019-12-14 00:03:01
问题 Hi I was wondering if someone could explain how to to make this method diplay a running count and average, and not just display it once the user has finished entering its data? public void InScreen() { int count = 0; double total = 0.0; double average = 0.0; double number; Console.WriteLine("Enter the set of scores (enter 0 to indicate end of set)"); number = double.Parse(Console.ReadLine()); while(number != 0) { total += number; count++; number = double.Parse(Console.ReadLine()); } if (count

Set tables as side by side instead of straight down while doing a while-loop

旧巷老猫 提交于 2019-12-13 23:56:48
问题 include 'inc.php'; $varVeh=$_POST['Veh_num']; $sql_course="select course_num from hc_course"; $results_course=mysql_query($sql_course); $sql_vehName="select Veh_name from hc_vehicle_type where Veh_num=$varVeh "; $result_vehName = mysql_query($sql_vehName); $vehName=mysql_fetch_assoc($result_vehName); echo "<table><tr><th>Best Scores for".$vehName['Veh_name']."</th> </tr></table>"; while($rc = mysql_fetch_array($results_course)){ $sql_HiScores = "SELECT c.course_name as course, e.distance as

Palindrome in Java with NUmbers [closed]

ぃ、小莉子 提交于 2019-12-13 22:40:51
问题 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 3 years ago . I am self studying java, i am on while loops already, I have an exercise here regarding a palindrome. what's a palindrome? how will code it? any ideas? or pseudocode for it? I am really confused here NOT a HOMEWORK 回答1: Since its not homework, it shouldn't matter how you implement

Wrong output from a while loop using indexOf [duplicate]

时间秒杀一切 提交于 2019-12-13 22:40:32
问题 This question already has answers here : While loop doesn't run a indexOf search (4 answers) Closed 5 years ago . I'm trying to find out how many times one string appears in another. For my testing, I'm using "ea" for wordOne and "Ilikedthebestontheeastbeachleast" for wordTwo. My output is returning 2 for my "appearance" variable, which should store how many times "ea" appears in wordTwo. It should return 3. I've tried messing with variable initializations, and trying to think of the math

PHP Table Loop?

末鹿安然 提交于 2019-12-13 22:05:23
问题 <?php $i=0; while($i < 101){ if($i%2==0){ echo "<tr>".PHP_EOL; } echo "<td>".$i."</td>".PHP_EOL; $i++; if($i%2==0){ echo "</tr>".PHP_EOL; } } ?> This code generates a table with 100 rows and 2 columns. But what I want to do is that show ordered numbers (upp to 100) in the left side of the rowcells and show something else (ex. pow(rownumber) ) in the right side of the rowcells. How can I do that? 回答1: Try this, Will output 100 rows with the number and its power in two columns <table> <?php for