while-loop

Guessing game in python

夙愿已清 提交于 2019-12-13 00:38:12
问题 I have only just started to learn to program following http://learnpythonthehardway.org. After learning about loops and if-statements I wanted to try to make a simple guessing game. The problem is: If you make an incorrect guess it gets stuck and just keeps repeating either "TOO HIGH" or "TOO LOW" until you hit crtl C. I have read about while loops and have read other peoples code but I simply dont want to just copy the code. print ''' This is the guessing game! A random number will be

Timing R code with Sys.time()

帅比萌擦擦* 提交于 2019-12-13 00:26:00
问题 I can run a piece of code for 5 or 10 seconds using the following code: period <- 10 ## minimum time (in seconds) that the loop should run for tm <- Sys.time() ## starting data & time while(Sys.time() - tm < period) print(Sys.time()) The code runs just fine for 5 or 10 seconds. But when I replace the period value by 60 for it to run for a minute, the code never stops. What is wrong? 回答1: As soon as elapsed time exceeds 1 minute, the default unit changes from seconds to minutes. So you want to

Idiomatic way to exit ksh while loop

假装没事ソ 提交于 2019-12-13 00:14:51
问题 I've the following 5 second timer which prints an asterisk for each second. timer () { i=1 trap 'i=5' INT while [[ $i -le 5 ]]; do sleep 1 printf "*" ((i+=1)) done } Somehow the trap chunk seems a little hackish and I wonder if there's a more correct way to interrupt the entire loop (not just the current sleep cycle). I've tried: trap 'print "foo"' INT at various locations inside and outside the function, but as I alluded to before, that just interrupts the current sleep cycle. 回答1: Perhaps I

How to loop an onEdit function to send emails from multiple rows in Google Sheets?

余生颓废 提交于 2019-12-12 23:13:53
问题 I'm very new to this and my job has a Google sheet that has all of our lead information from FB, and I'm trying to have a function (onEdit) that will send out an email to the lead based on one cell's data. For example, when A2 contains "Follow Up", then it sends out an email to the address in D2, and the body text comes from J2 (the canned response for the "Follow Up" data validation). Right now this works for row 2, however when inputting "Follow Up" in any other row it sends every row in

loop is too slow for IE7/8

♀尐吖头ヾ 提交于 2019-12-12 22:56:00
问题 I have a loop execution that needs to run in all browsers. in chrome/ff etc the execution runs fast and fine. in IE it's slow and end's up dispatching a prompt saying a script is running slow (no good). Any ideas on how to get around something like this? I mostly just need to get rid of the IE prompt for 7/8 ** edit ** Here's code: if(this.handicap()) { while(this.hasGraphChanged()) { this.gravity(this.separate()); } } This is a VERY large project, so instead of listing all the code, I'll go

How do create perpetual animation without freezing?

。_饼干妹妹 提交于 2019-12-12 22:51:19
问题 I am still a newbie at Javascript. I tried writing a program to make images fadeToggle all the time, so I used the while conditional statement (combined with a constant variable); after running that and freezing my computer (then remembering that viruses are basically infinite operations) I searched on here a bit, realized I should probably, indeed, never use infinite loops. (Actually I want shimmer -- meaning to go from opacity 0.9 to 0.6 to 0.9 etc...) so its not the same as fadeToggle, but

udp socket programming file transfer

泪湿孤枕 提交于 2019-12-12 19:59:51
问题 Server Side Code......... #include<stdio.h> #include<string.h> #include<stdlib.h> #include<arpa/inet.h> #include<sys/socket.h> #define BUFLEN 503 #define PORT 8885 void die(char *s) { perror(s); exit(1); } int main(void) { struct sockaddr_in si_me, si_other; int s, i,j, slen = sizeof(si_other) , recv_len; char buf[BUFLEN]; if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) { die("socket"); } memset((char *) &si_me, '1', sizeof(si_me)); //printf("%d",si_me); si_me.sin_family = AF_INET; si

How to make a 20 rows x 50 columns grid in java

笑着哭i 提交于 2019-12-12 19:51:22
问题 I'm trying to make a grid made out of "." for a MineSweeper/Capture The Flag type game, but I've been having trouble. I'm trying to do a \n every 50 "." so it can start printing another column but my code prints a single dot every row. This is how the grid is supposed to look (ignore the % and the since that's another part of the project, pretend it is alll "."): https://imgur.com/a/3zWKyb8 This is my code: String grid = "."; int rows = 20; int columns = 50; int count = 0; while(count <= 1000

While Loop Alternative in Python

一个人想着一个人 提交于 2019-12-12 19:29:16
问题 I am working on a huge dataframe and trying to create a new column, based on a condition in another column. Right now, I have a big while-loop and this calculation takes too much time, is there an easier way to do it? With lambda for example?: def promo(dataframe, a): i=0 while i < len(dataframe)-1: i=i+1 if dataframe.iloc[i-1,5] >= a: dataframe.iloc[i-1,6] = 1 else: dataframe.iloc[i-1,6] = 0 return dataframe 回答1: Don't use loops in pandas, they are slow compared to a vectorized solution -

How to accept input without the need to press enter Python 3 [duplicate]

空扰寡人 提交于 2019-12-12 19:23:16
问题 This question already has answers here : raw_input in python without pressing enter (7 answers) Closed 5 years ago . i'm wondering how to accept input without the need to press enter. i searched online, and i get something regarding raw_input, but i think that became obsolete after the arrival of python 3.0. sometimes, i run a while loop on a whole program since i want to ask the user: continue? (y/n): for instance consider the code: import random d = input('Toss coin? (y/n): ') while d != 'n