Linked Questions

2 votes
7 answers
6k views

I am creating a car game. There are only "start", "stop", "quit" commands. Any other command is not recognized. command = "" while command != "quit": ...
toothpick's user avatar
  • 125
3 votes
4 answers
182 views

here is my code: def is_prime(x): if x < 2: return False else: for i in range(2,x): if x % i == 0: return False else: ...
user3454635's user avatar
0 votes
1 answer
2k views

Given the following Python program, #Version 1 x = 15 y = 8 while x - y > 0: x -= 2 y += 1 print x, y if x % y == 0: break else: print x, y The output comes as: 13 9 11 ...
Dr. Debasish Jana's user avatar
-2 votes
2 answers
882 views

I have just started to explore python recently. So, I read about while else in python which sounds awesome but I am failing to execute a simple code, what am I am missing? env: python 3.8.5 (anaconda) ...
Genocide_Hoax's user avatar
0 votes
1 answer
302 views

I was going through this. Coming from C environment, it hit me right in the face with utter surprise and disbelief. And, then I tried it for myself:: bCondition = True while bCondition: print("...
Abhineet's user avatar
  • 5,429
0 votes
2 answers
141 views

Learning python, found this code snippet. It reads text from stdin and prints "Done" when it finishes. I've never seen an else for a while loop anywhere else in any other language. The comments on the ...
user avatar
1 vote
1 answer
258 views

I came across some code that has the structure: for val in list: do_something(val) if val is x: break else: do_something_else() I couldn't find much information about this structure ...
flau's user avatar
  • 1,398
-1 votes
1 answer
176 views

My question is why there is such a thing as an "else" clause in a while loop. My code, for example, looks like this: a = 100 turns = 0 while a > 0: if func(a, b): #Function returns boolean ...
OscarVFE's user avatar
-2 votes
1 answer
50 views

Please help. I am so sorry but I cannot find an answer to make the loop stop after three questions. I've searched for two days. I am brand new at this and trying to teach myself. Everything runs ...
Brenda's user avatar
  • 1
764 votes
40 answers
834k views

Given the following code (that doesn't work): while True: # Snip: print out current state while True: ok = get_input("Is this ok? (y/n)") if ok.lower() == "y&...
Matthew Scharley's user avatar
795 votes
26 answers
361k views

I understand how this construct works: for i in range(10): print(i) if i == 9: print("Too big - I'm giving up!") break else: print("Completed successfully&...
Kent Boogaart's user avatar
304 votes
22 answers
813k views

Is there a goto or any equivalent in Python to be able to jump to a specific line of code?
user46646's user avatar
  • 160k
60 votes
5 answers
107k views

I have a Python script: if True: if False: print('foo') print('bar') However, when I attempt to run my script, Python raises an IndentationError: File "script.py", line 4 ...
Chris's user avatar
  • 23.2k
17 votes
4 answers
10k views

Why does PyCharm highlight the boolean variable nearby the return with Local variable "boolean" might be referenced before assignment? This code checks whether a number is prime or not: import ...
Mikeros's user avatar
  • 173
11 votes
5 answers
47k views

What is the Java equivalent of the while/else in Python? Because it doesn't work in Java. The first chunk was my python code and the second portion is my attempt to translate it into Java. Edit: tring ...
MissSprezzatura's user avatar

15 30 50 per page