while-loop

While Loop Guessing Number Game - Python

回眸只為那壹抹淺笑 提交于 2019-12-13 10:11:50
问题 I'm trying to make a 'guess the number between 1-10' game but the while loops seems to keep running. I want to program to let the user guess a number then display if its too high or low etc then start again automatically (loop) to allow the user to pick again. This code makes it run forever though. Can you guys help me? import random def numberGuess(): printNow("I'm thinking of a number between 1 and 10") guess = 0 # give guess a starting value randNum = random.randrange(1,11) # this line

How to count min,max in loop (java) [closed]

心已入冬 提交于 2019-12-13 09:59:11
问题 This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 7 years ago . I have problem with coding 1 app for toomorow lectures. So, That program ask user for numbers, on typed "100" it's stops, and it shows: -average -min

JavaScript Console not starting loop. No apparent bugs can be found

℡╲_俬逩灬. 提交于 2019-12-13 09:54:45
问题 I am trying to write some which starts from 86400 and counts down all to way to 0. But when I create the loop, the console would not display anything. Any help would be greatly appreciated! let date = new Date(); let hour = date.getHours(); let min = date.getMinutes(); let sec = date.getSeconds(); let hourToSec = parseInt(hour) * 3600; let minToSec = parseInt(min) * 60; let currentSec = hourToSec * minToSec * sec; let remTime = 86400 - currentSec; while (remTime > -1) { console.log(remTime);

My code to write a .txt file from my @data isn't working :(. What am I doing wrong? I am using a while loop

大兔子大兔子 提交于 2019-12-13 09:49:56
问题 iv. Write the following output to a new file with columns separated by tabs ("\t"): DATE, MONTH, MAX TEMP, MIN TEMP, MAX HUMID, MIN HUMID #a declare vars @riteline=(); my $headers; my $riteAline; print 'iv. Write the following output to a new file with columns separated by tabs ("\t"):'; print "\n DATE, MONTH, MAX TEMP, MIN TEMP, MAX HUMID, MIN HUMID"; $headers= ("DATE,MONTH,MAX TEMP,MIN TEMP,MAX HUMID,MIN HUMID"); $headers=~ tr/,/\t/; #first you can turn the arrays into string open (my $fh,'

What is the usage of while(1)? [closed]

谁都会走 提交于 2019-12-13 09:47:14
问题 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 . Can anyone explain the usage of while(1)? I am a beginner in c++ & want to know when should I use while(1)? And how can I use it? Please give an example to explain. Thanks in advance. 回答1: Well, for embedded bare metal code it's often written like this: int main() { while(1) {

Array pairwise matching in java give error also store data between two similar element

穿精又带淫゛_ 提交于 2019-12-13 09:44:34
问题 I have two array. They are represent x-coordinates and y-coordinates. The code is like that if both coordinates are same it print a statement "Both co ordinates are same" else they print They are not same . My code is public static void main(String args[]){ double[]xcoordinate={2.3,1.2,3.3,5.5,2.3,1.3,7.9,1.2,3.3,3.3,5.2}; double[]ycordinate={5.4,2.2,4.4,6.6,5.4,1.9,5.2,2.2,3.5,4.4,4.2}; int i=0,k=1; while(i<xcoordinate.length){ //if(xcoordinate[i]&&ycordinate[i]==xcoordinate[k]&&ycordinate[k

Java - Nested loops - Having trouble getting any output

不羁岁月 提交于 2019-12-13 09:41:17
问题 I came up with this idea to simulate the way a plant grows. The idea is based off of fractal geometry and basically how that explains the repetitions of branches and other structures in plants. I am very much a beginner with programming, though, so I thought I'd test out JUST the basic logic of repeating something. Below is what I wrote in Java. /* Java program: plant.java This program runs a loop simulating plant growth. The idea is that the plant will continue to have "repeated" growth and

Try-Catch inside a loop

百般思念 提交于 2019-12-13 09:35:47
问题 In the below code, I ask the user to give an integer input and if the input is 0 or a negative number, it loops again until the positive number is given. The thing is that if the users presses a letter, my code crashes and despite the fact that I used try-catch in a lot of ways nothing really worked. Any ideas? I used try-catch inside the loop, but it only worked for one letter input and not correctly. System.out.print("Enter the number of people: "); numberOfPeople = input.nextInt(); while

How to make a loop to print the following pattern?

巧了我就是萌 提交于 2019-12-13 09:29:54
问题 I want to write a program that prints out the following pattern by using loop. Right now I am able to print it by using only system.out.println . I have no idea which loop I should make. The pattern will be: * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * My code: package pettern; public class Pettern { public static void main(String[] args) { //initializing String tenStar = "* * * * * * * * * *"; String NineStar = "* * * * * * * * *"; String

How to populate an array list in a while loop

空扰寡人 提交于 2019-12-13 09:27:04
问题 My problem is this Scanner sf = new Scanner(f); ArrayList<String> teamArr = new ArrayList<String>(); int counterPopulate = 0; while(sf.hasNextLine()){ teamArr[counterPopulate] = sf.nextLine(); counterPopulate++; } Any solutions, this is surrounded by a try catch. Getting the problem at this part teamArr[counterPopulate] = sf.nextLine(); 回答1: Because ArrayList is different than normal arrays , you need to use methods of the ArrayList class to populate the ArrayList . In your case you need to