while-loop

tkinter root.mainloop with While True loop

和自甴很熟 提交于 2019-12-02 13:18:37
问题 I am using tkinter to display some labels based on voltages I am reading. However, it stops executing after one read. I have found that it is due to root.mainloop(). But I am not able to fix it. I have included my code. The root.mainloop() is located right at the end of the while True. from Tkinter import * import spidev import time import os import RPi.GPIO as GPIO import numpy GPIO.cleanup() GPIO.setmode(GPIO.BOARD) GPIO.setup(7, GPIO.OUT) GPIO.setup(11, GPIO.OUT) GPIO.setup(13, GPIO.OUT)

Why does this do-while loop not produce the right output?

痞子三分冷 提交于 2019-12-02 13:17:39
public static void main(String[] args) throws IOException { System.out.println("Hello, come and play a game with me!"); int x = 5; int guess; do { System.out.println("Please input a number..."); guess = System.in.read(); guess = System.in.read(); if (guess < 5) { System.out.println("You guessed the number!"); break; } } while (guess > 5); } So here I wrote some code. It's supposed to be a guessing game, but no matter what I input, it always gives me in the output "Please input a number..." NO MATTER WHAT I PUT. Basically, if the "guess" is more than 5, then they guessed the number. If it's not

Python - Infinite While Loop

点点圈 提交于 2019-12-02 13:17:22
I do not understand why the while loop at the bottom is an infinite loop. # User enters a positive integer number user_input = int(input('Please enter a positive integer number: ')) # Make the epsilon value a constant EPSILON_VALUE = 0.0001 # Choose an initial estimate - set the initial estimate e=x estimate = user_input # Evaluate the estimate - dividing the value x by your estimate e, result = user_input / estimate # Calculate the difference difference = abs(estimate) - abs(result) # If the difference is smaller than your epsilon value, then you've found the answer! if difference <= EPSILON

NullPointerException in while loop when trying to add new Class instances to ArrayList

折月煮酒 提交于 2019-12-02 13:17:19
The more I google this the more confused I'm getting. I'm bringing in a list of names of unknown length with some other details in from a CSV which I then need to turn into Person objects and store in a list called people which is the instance variable for the class Club, a list of its members basically. This is a very simplified version of something more complex I need to do in which I need to while loop through a file creating objects for each line which I then need to add to a list collection. I keep getting a nullPointerException error when I run my code though and I'm stumped how to avoid

c++ for loop converted to a while loop

泪湿孤枕 提交于 2019-12-02 13:06:43
Hi I wrote this code to print out factors of an integer with a for looop how do i write it with a while loop? for(int i = 1; i < integer+1; i++) { if(integer % i == 0) cout<< i<<" "; } int i = 1; while (i < integer+1) { if(integer % i == 0) cout<< i<<" "; i++; } Or even better: int i = 0; while (++i < integer+1) { if(integer % i == 0) cout<< i<<" "; } int i = 1; while(i < integer + 1) { // your current loop body goes here i++; } See equivalent forms of for loop . Following code will print the same result as your for loop in printing. int i = 1; while(i < integer + 1) { if(integer % i == 0) {

What is the logic of this process

為{幸葍}努か 提交于 2019-12-02 13:03:09
问题 I was working on a problem in Project Euler; and I found a question in SO. The question and accepted answer says; n = 600851475143 i = 2 while i * i < n: while n%i == 0: n = n / i i = i + 1 print (n) It's just awesome. I still can't understand how this process is so fast and can find the largest prime factor of 600billion in 0.00001 seconds. I tried tons of methods and codes for that, processes took over than 1 hour.. Could anyone explain me the logic of this codes and why it's super-fast? is

Variable issues in SSH

跟風遠走 提交于 2019-12-02 12:43:48
Hey guys I'm trying to run this code: #!/bin/bash sudo /usr/local/bin/sshpass -p pwd ssh -o stricthostkeychecking=no -p 11022 admin@$1.test.com<<EOI i=1 while read line do location="sudo sed -n ${i}p /Users/Shared/$1.txt" number="sudo sed -n ${i}p /Users/Shared/$2n.txt" my_array=("${my_array[i]}" $line) sudo cp /Applications/TEPS\ OS\ X\ Share\ Folder/MAIN\ IMAGES\ FOLDER\ ƒ/${location}${number} /Users/Shared/FYP/$number sudo sips -Z 256 /Users/Shared/FYP/$number /Users/Shared/FYP/$number ((i++)) done </Users/Shared/$2.txt exit EOI basically it reads a text file which gives the location of

Java SE do while loop issues

久未见 提交于 2019-12-02 12:37:24
I have a problem with my java application when i compile my codes it says that it cannot find symbol roomLength . what the application supposed to do is prompt the user to input a room name then if it is "quit" then it has to close the program. otherwise it will prompt for the length, width and height of the room. if any of these dimensions is zero or lesser, it will reprompt for the dimensions again. class Room { private String name; private double length; private double width; private double height; public Room(String r, double l, double w, double h) { name = r; length = l; width = w; height

Python looping and program restart if true

混江龙づ霸主 提交于 2019-12-02 11:52:17
Please help as I am a true beginner and would love to learn more. I am trying to learn more about looping so take a look at this code please. # lets the user input first number num1 = float(raw_input("Enter your first number ---> ")) # lets the user input second number num2 = float(raw_input("Enter your second number ---> ")) #the next four lines sets the basic mathematical equations addAns = num1+num2 subAns = num1-num2 mulAns = num1*num2 divAns = num1/num2 # ask the user to let the program know what equation to run with an option of running them all operator = raw_input("What operator would

How to precalculate valid number of combinations instead of using while loop?

橙三吉。 提交于 2019-12-02 11:52:05
Given List of datacenters which are dc1, dc2, dc3 and list of machines, h1, h2, h3, h4 as mentioned below - Datacenters = dc1, dc2, dc3 Machines = h1, h2, h3, h4 I want to generate below combinations only - a) {dc1=h1, dc3=h3, dc2=h2} b) {dc1=h2, dc3=h4, dc2=h3} c) {dc1=h3, dc3=h1, dc2=h4} d) {dc1=h4, dc3=h2, dc2=h1} Each datacenter in the each pass should get alternate machines/hosts. They should not get same machines. For example in a as shown above - dc1 gets h1 , dc2 gets h2 , dc3 gets h3 so all the machines are different for each datacenters. And in the second pass as shown in b - now dc1