Does anyone know how to fix this loop error in my code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Does anyone know how to fix this loop error in my code?

Does anyone know how to fix this loop error in my code? A = 1 While A == 1:{ If A == 1 :{ Print(“hi”) } } It keeps saying the ‘if’ is the problem “ if A == 1 :{ ^ “ It also says invalid syntax in pythonista And I know I want it to repeat forever

21st Mar 2023, 1:01 AM
Asher Balinski
Asher Balinski - avatar
3 Answers
+ 3
Asher Balinski There is no curly braces in python for conditional statement or loop or function
21st Mar 2023, 5:44 AM
A͢J
A͢J - avatar
+ 4
There are a couple of issues with the code you provided. Firstly, the syntax of the while loop and the if statement are incorrect. Secondly, you have an infinite loop because the value of A is not changing, so the while loop will continue to run indefinitely. Here's a corrected version of your code: A = 1 while A == 1: if A == 1: print("hi") A = 0 # Add this line to change the value of A and break out of the loop In this version, I removed the curly braces around the while loop and the if statement, and corrected the indentation. I also added a line to change the value of A and break out of the loop, so the program doesn't get stuck in an infinite loop.
21st Mar 2023, 1:18 AM
Hasnain [ACTIVE CHALLENGER]
Hasnain [ACTIVE CHALLENGER] - avatar
+ 3
Here is the real code. up there is a basic idea while repeat == 1: Daze = 0 if repeat == 2: monster = monster +1 { if Bb == 1:{. <<<This one here print("The "+ MnLv "ranked leader appears to stop you") } else{ print("a monster appears and is ready to brawl") } }
21st Mar 2023, 1:21 AM
Asher Balinski
Asher Balinski - avatar