Need help understanding this while loop - Python discussion
Feb 13, 2024 ... I'm new to while loops, and I don't quite get what's going on in this code from my book: current_number = 1 while current_number <= 5: ...
Feb 13, 2024 ... I'm new to while loops, and I don't quite get what's going on in this code from my book: current_number = 1 while current_number <= 5: ...
Dec 21, 2022 ... ... loop will be seen outside the loop. In simple terms, Python runs one line of code at a time. If you start at the top of the script, and ...
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 ...
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.
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.
Oct 5, 2021 ... while True: age = float(input("Enter your age")) if age == 0.0: sys.exit("Process finished with exit code 0") ... although ...
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 ...
Nov 8, 2022 ... ... while loop, which I don't think was your intention. A more general piece of advice, your program has way too many code paths. It's quite ...
Nov 6, 2021 · But strings are funny: there is no “character” type in Python, for iterating over a string just gets you a series of single character strings, and strings are iterable. SO all () does not raise an exception. For your code, this is a little misleading. Finally, all (e) checks the truthiness of everything in e. The
Jun 25, 2024 ... Hi there, I'm new to python. I just finished eric matthes crash course book and working on my first script. Its a program that calculates ...
May 6, 2024 · The body inside of a loop should be the code that you are running. It generally isn’t for defining functions. That is kind of like assigning the same value to a variable over and over again.
Jan 28, 2023 ... You don't import time , though I suspect that you didn't copy the code exactly as you've been running it (there's a stray < there too).