Help with a while loop - Python Discussions
Feb 5, 2024 ... Christopher : quest1s = input("?: ") while quest1s != (organs, cells, organisms, tissues, organ_system): word = input("That is not A, B, C, ...
Feb 5, 2024 ... Christopher : quest1s = input("?: ") while quest1s != (organs, cells, organisms, tissues, organ_system): word = input("That is not A, B, C, ...
I have while j < n in the first while loop and also in the inner loop. I could not see a way to simplify the two while j < n statements.Can you give an example or two of input and expected output? Or link to a discussion where the expected behaviour is described?
Oct 20, 2021 · Thanks. You can use nested for loops controlled by the user’s input. Here is a suggested header for the outer loop: ... Are you familiar with the documentation on the official Python web site? See Built-in Functions. The following may be particularly helpful for this project. chr () ord () Those functions may help you translate between ...
Jun 9, 2022 ... This code has a some string swapping but otherwise is simple and very readable. ... program it all linearly and learn about strings and loops.
For-loops are also faster than while loops. Also, it is not generally correct to write Windows paths using raw strings. Raw strings are designed for regexes, and there are legal Windows paths which are illegal raw strings. Just use forward slashes.
Sep 18, 2025 · Hello, I am new to Python and currently learning while loop inside a for loop. In the code ,I have a couple of questions: Does the execution engine cursor go back to the closest loop as it is done with executing the block of code.
Jan 17, 2023 ... file.readline() reads a line. That's always a string. The line will usually end with "\n" , although the last line might not.
Apr 27, 2022 · Python has semantic indentation, so it’s hard for a human to tell what your code is doing without the leading spaces and impossible to actually run it. Please edit your post to enclose all of the code in a “preformatted text” block, either by adding triple backticks (```) before and after the code, or by highlighting the code and clicking ...
Jun 4, 2026 ... That said, a while loop is concept related to control flow, they're not a python exclusive feature and basically any programming language uses ...
Hey Quercus. Thanks for the quick response. I’m still newer to python, but trying to get the hang of it. Since the last line in my text doc is an empty string, I expected that that would trigger the end of the while loop (since the condition would be met). Is this incorrect?
Jun 18, 2024 · A while loop means “repeat the following block of code until the condition is not met.” The loop is set to run while (i < 18), but then i is overwritten by i=int (input (“Enter your height:”)). So any value for height less than 18 will cause the loop to stop once it finishes the current iteration. To my eye the loop logic is a bit odd, because it at least starts examining the age (in ...
Dec 21, 2022 ... The while loop does not effect code outside the loop except that changes to variables and data inside the loop will be seen outside the loop ...
Nov 3, 2023 · The way that python changes the value of a variable is to use =. = does not mean equality as it does in mathematics. To set counter to 0 you have this line of code: counter = 0 Inside the loop the value of counter needs to be incremented by 1 each time. counter = counter + 1 What that does is take the current value of counter, add one to it and replace the value in counter with the calculation ...
Oct 19, 2022 · By starting at -1 your loop test now needs to test against size-1, which is more… complicated than size. More complication means harder to read and understand. It is also why functions like range () exist: to make it easy to use the values you want. When you’re looking for this kind of error, it helps to call print () with various ...