Skip to content
murmot

Results for “python while loop string example interview site:discuss.python.org”

  • discuss.python.org

    While loop Problem - Python Help - Discussions on Python.org

    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 ...

  • discuss.python.org

    Need help understanding this while loop - Page 2 - Python Help...

    Can a for loop do anything a while loop can do, and better? Good question; the answer depends on what you mean by “this kind of iteration”.For a simple loop, I prefer for loop as it feels natural and easy to me. Consider your example in the 1st post, it is simpler in for loop as follows

  • discuss.python.org

    Struggling with combining while loop, if statement and try block

    I can handle writing the function for one of these scenarios (ie. erroring and looping back if the user enters a year outside the range) but when I try and combine them im getting really confused. I tried nesting an if block in a try block in a while loop but it wasnt working.

  • discuss.python.org

    Python “while” loops, and how they kill me

    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 ...

  • discuss.python.org

    How while loop wroks? - Discussions on Python.org

    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 ...

  • discuss.python.org

    Infinite While Loop - Python Help - Discussions on Python.org

    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?

  • discuss.python.org

    How to while-loop .readline see str in the file - Python Help ...

    Jan 17, 2023 · A file is a line iterator. Use str.rstrip to remove any whitespace, including newlines, at the end of a string. for row in file: row = row.rstrip() <continue processing row> Use strip to also remove whitespace at beginning. Use if row [-1] == '\n': row = row [:-1] to only remove a newline.

  • discuss.python.org

    While Loop Inside a For Loop - Python Help - Discussions on ...

    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. For instance, after count +=1, does it go back to the while condition again to test it before it goes to the outer for loop? Does the engine treats the block of code ...