0
What's the mistake
7 Antworten
+ 5
Lullaby
Don't use bad language like code name on learning platform
+ 5
Lullaby , Wong Hei Ming ,
here is what the python docs are saying to `else clause` in a `for loop` or in a `while loop`:
> https://docs.python.org/3/tutorial/controlflow.html#break-and-continue-statements-and-else-clauses-on-loops
+ 3
Start with the error your code gives you when you run it. It is pointing you in the direction you need to look first.
Hint: comparison operators
Don't forget, Google is your friend. Learning to code has sharpened my googling skills.
+ 3
Although there are mistakes in the code I learned something new.
With the original code, “while” and “else” are in the same level. After fixing other errors and run the code, it prints “Done”, which surprised me. I didn’t know “while” and “else” can put on the same level. It almost the same as “if…else…”, but “if” is replaced by “while”. And I found w3schools does have an example of this usage!
+ 1
i=0
while i <= 10:
i=i+1
if i==5:
continue
print(i)
else:
print ('Done')
# 1. comparison operator <=
# 2. no colon after while statement
# 3. indentation error - print(i)
# 4. Relocate print function to allow continue to skip the printing when i=5
# 5. Using an obscenity as a code name is your biggest mistake & may get you banned from this site
+ 1
Add a second = to the i = 10 like this i == 10
0
Aj coming in clutch totally helping solve the problem