while-loop

Why is my function only splitting the last line in a data file?

Why is my function only splitting the last line in a data file? Question: I’m supposed to be writing a function that will read data from a .txt file and build a dictionary. The headers of the txt file will be the keys, and the values under each header will be values assigned to each …

Total answers: 1

Automatically restarting killed Python process executed within a multiprocessing.Pool

Automatically restarting killed Python process executed within a multiprocessing.Pool Question: I have the following code: import multiprocessing import urllib.request from time import sleep connected = False def check_internet_connection() -> None: while True: print(f’inet’, flush=True) try: urllib.request.urlopen(‘https://www.google.com’, timeout=1) connected = True except urllib.request.URLError: connected = False finally: sleep(5 – time.time() % 5) def loop(delay: float = …

Total answers: 1

Why is my python3 function running without being called?

Why is my python3 function running without being called? Question: Using python3.8 on macOS I have a function with a while loop inside, and i also import two other .py files from the same directory which contain functions i need. import Scraper import Creator def main(index=1): operation = True while operation == True: try: Scraper.scraper() …

Total answers: 1

Why is the while loop not ending

Why is the while loop not ending Question: holes = int(input("Enter number of holes")) if holes == 18 or holes == 9: print(holes, "holes") else: while holes != 18 or holes != 9: holes = int(input("18 or 9 holes only.")) Asked By: newbee || Source Answers: Because if it holes is 18, then it isn’t …

Total answers: 1

I have just started coding and am stuck solving this python problem

I have just started coding and am stuck solving this python problem Question: Write a program that always asks the user to enter a number. When the user enters the negative number -1, the program should stop requesting the user to enter a number. The program must then calculate the average of the numbers entered …

Total answers: 1

I need help in my while loop conditions in python

I need help in my while loop conditions in python Question: I created a game, in which there is a secret number, and you guess, then the computer guesses. The secret number changes every round. To win, either you or the computer needs to get a score of 2. I don’t know how many rounds …

Total answers: 2

How to increment an integer in a list iteratively within a while loop

How to increment an integer in a list iteratively within a while loop Question: Can anyone help me with understanding this please? I’m using a while loop to increment an integer within a list and then i’m trying to add the list to another list to create a list of lists. The list of lists …

Total answers: 3

ValueError; low >= high

ValueError; low >= high Question: I am getting "low >= high" error in the loop code below, how can it be resolved? while True: max_num = 1000 num_1 = np.random.randint(1, max_num) num_2 = np.random.randint(1, max_num) if (num_1 < num_2): num_2 = np.random.randint(1, num_1) break Asked By: Emir || Source Answers: In your condition: if (num_1 …

Total answers: 2

how to indent and stack while loops in python?

how to indent and stack while loops in python? Question: I have a problem stacking while functions to make an algorithm that fills black an image except where it’s black within a 2d array the image i want the algorithm to go along the columns anf fill black and when it encounters color it goes …

Total answers: 1

How to implement a while loop to continue taking the latest value?

How to implement a while loop to continue taking the latest value? Question: I have created the below bank project where the while loop is always taking the total amount as 100 and continue the loop as long as user select ‘yes’. However I would like the while loop to take the latest total amount …

Total answers: 2