+ 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")

16th Feb 2020, 7:25 PM
Alisher Berdibekov
Alisher Berdibekov - avatar
32 Antworten
+ 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?
16th Feb 2020, 8:45 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 12
Well.. it is outside the loop...? Put everything inside the loop.
16th Feb 2020, 7:29 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
17th Feb 2020, 2:25 AM
Sonic
Sonic - avatar
16th Feb 2020, 8:28 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
Check your indentation of that line of code in relation to the while loop
16th Feb 2020, 7:45 PM
Rik Wittkopp
Rik Wittkopp - avatar
+ 4
Alisher Berdibekov I think this video is a good introduction for indentation with if/else statements: https://youtu.be/DZwmZ8Usvnk
16th Feb 2020, 9:16 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
16th Feb 2020, 9:30 PM
Mihai Apostol
Mihai Apostol - avatar
+ 4
Put your quit in quotes. if operation == "quit": break
17th Feb 2020, 2:25 AM
Bishow Pandey
Bishow Pandey - avatar
+ 3
Write it in code playground, and then share it please.
16th Feb 2020, 7:43 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
Alisher Berdibekov an example with if statement: if False: print(1) print(2) OUTPUT: 2 if False: print(1) print(2) OUTPUT: None
16th Feb 2020, 8:51 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 3
Alisher Berdibekov yes, indentation is how things are done. Let me try and find a video where it is well explained.
16th Feb 2020, 9:09 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
Did you fix it?
16th Feb 2020, 7:41 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
16th Feb 2020, 8:09 PM
Alisher Berdibekov
Alisher Berdibekov - avatar
+ 2
Do you know what indentation is?
16th Feb 2020, 8:39 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 2
so basicaly it printed 2 in first example because its in the one loop?
16th Feb 2020, 8:53 PM
Alisher Berdibekov
Alisher Berdibekov - avatar
+ 2
Ive already answered, but pass, not break
17th Feb 2020, 7:59 PM
TheAmmiR
TheAmmiR - avatar
+ 1
yes
16th Feb 2020, 7:41 PM
Alisher Berdibekov
Alisher Berdibekov - avatar
+ 1
still no, idk how to place break so it stops showibg me this error
16th Feb 2020, 7:42 PM
Alisher Berdibekov
Alisher Berdibekov - avatar
+ 1
can you explain me what I did wrong? i still cant
16th Feb 2020, 8:34 PM
Alisher Berdibekov
Alisher Berdibekov - avatar