I’m trying to understand the walrus assignment operator. Classic while loop breaks when condition is reassigned to False within the loop. Why doesn’t this work using the walrus operator? It ignores the reassignment of x producing an infinite loop. Answer You seem to be under the impression that that assignment happens once before the loop is entered, but that isn’t
Tag: while-loop
repeating a program using while loop failed
I coded a program that is meant to repeat itself over and over until the to_continue loop is broken by the input “N”. However, it didn’t seem to work. Output: whilst I meant for it to output Full program if that’s helpful: Any help would be deeply appreciated :) Please comment if any of the explanations are unclear or if
Compare each element of a list in existing order with elements of a second list in order as long as items in lists are equal
Compare each element of a list in existing order with elements of a second list in existing order as long as items in lists are equal. Stop if they’re not equal and give me as result the index and name of the last match. I thought it’s straightforward with a while loop but it seems like this has to be
Should I be using an if statement or a loop?
It’s me, your friendly Python noob! I’m working on this program and I’m trying to figure out how to get the program to stop if the number exceeds a certain threshold OR if the user enters anything other than a number to loop back around and try again. Here is what I have so far: The if statements in main()
Python while loop not working as intended
I don’t know how to get over this problem with while loop. So basically I want to return the number of zeros at the end of a number’s factorial. After the while loop runs only 1 time, it breaks; I don’t know why. Help would be very appreciated. Thanks! Answer After multiplying your value by 0.1 it becomes a float,
Iteration numbers with True False condition
Please HELP!! I have a list: I want to generate iteration number if it’s False the number continues and if it’s True the number stays. I Try this code: it’s just keep running and did not show any output. the desired output will be [1,2,3,3,3,4,5,6,6] I have no idea what’s wrong with it Thanks Answer Yet another version of this
Using primitive operators to find factorial of N up to K depth
Having difficulty coming up with a solution using: iteration/control-flow and accumulation. More than just a solution, would prefer having an answer with hints and explanation. Answer Ignoring k=0 you have want to multiply k numbers starting with n and ending with n-k. The above loops k times and since i will increment by 1 starting from 0, you can simply
While loop spamming output instead of printing output once?
I’m making a regular guess the number game. I’m having problems when I enter the guess and the program spams lower or higher instead of just typing it once, since I’m using a while True loop. Here I’m just opening the CSV file and picking a random number. Here I’m importing numbers 1-50 and picking two random numbers which will
Need help to make while loop restart my Python program from top
I would like to get help with this program I have made. The function of the code is so the users can input a city anywhere in the world and they will then get data about the weather for that city. I want it to restart the program from the top, but it only restarts the program from where the
Printing lines in a text file given line numbers
I am having trouble with a while loop statement for the question below. This is for a txt.file. ‘Write a program that allows the user to navigate through the lines of text in any text file. The program prompts the user for a filename and copies the lines of text from the file into a list. The program then prints