+ 2
Help. Me. Please.
Apparently I have something wrong, with “break”, to be more exact. It’s always outside loop, and IDK how to fix it. Any ideas? while True: print("Options:") num1 = int(input("Enter number")) num2 = int(input("Enter another number:")) operation = input("Enter your operation:") if operation == quit: break elif operation == "+": print("The answer is " + str(num1 + num2)) else: print("wat")
31 odpowiedzi
+ 7
Alisher Berdibekov Indentation is the most important thing in python.
A code is made of blocks of instructions. To determine blocks, we use indentation.
Let say we have a loop, to know which part will be looped, and which will not, this is how:
for i in range(10):
print(1)
print(2)
This will print 1 ten times, and then 2. Now the second code:
for i in range(1):
print(1)
print(2)
This will print 1 2 ten times, and not just one.
Did this make things clear?
+ 12
Well.. it is outside the loop...? Put everything inside the loop.
+ 6
If all else fails try this:
https://code.sololearn.com/cjgJT9aXLzs5/?ref=app
+ 5
Indentation:
https://code.sololearn.com/cCRNU76bAoZC/?ref=app
+ 4
Check your indentation of that line of code in relation to the while loop
+ 4
Alisher Berdibekov I think this video is a good introduction for indentation with if/else statements:
https://youtu.be/DZwmZ8Usvnk
+ 4
This could help also:
https://code.sololearn.com/cT5BRIbkia21/?ref=app
+ 4
Put your quit in quotes.
if operation == "quit":
break
+ 3
Write it in code playground, and then share it please.
+ 3
Alisher Berdibekov an example with if statement:
if False:
print(1)
print(2)
OUTPUT: 2
if False:
print(1)
print(2)
OUTPUT: None
+ 3
Alisher Berdibekov yes, indentation is how things are done. Let me try and find a video where it is well explained.
+ 2
Did you fix it?
+ 2
Do you know what indentation is?
+ 2
so basicaly it printed 2 in first example because its in the one loop?
+ 2
Ive already answered, but pass, not break
+ 1
yes
+ 1
still no, idk how to place break so it stops showibg me this error
+ 1
can you explain me what I did wrong? i still cant