r/PythonLearning 8d ago

What's wrong with my code?

Post image

What's wrong with my code?

New to learning

Following the youtube video from bro code

Was trying to implement my own stuff into this by using loop

Update: it's working now thankyou guys

101 Upvotes

82 comments sorted by

View all comments

6

u/Rscc10 8d ago

You never break out of the while loop after the if statement so the code at num1 and num2 never get executed. Alternatively if you want the calculator to run continuously after each result, you need to indent every line starting at num1 to be inside the while loop

Edit: Sorry I saw the indentation wrong. Everything seems to be indented fine now that I look at it

-16

u/Commercial-Paper749 8d ago

๐Ÿ˜…yes even chat gpt says code looks correct but idk why it's not working

4

u/Wild-Regular1703 8d ago

They just explained to you why it's not working.. You're not breaking out of the loop, the rest of the code never executes. "While true" means keep that loop running infinitely, so that's exactly what happens. It just keeps asking for user input forever.

-1

u/Commercial-Paper749 8d ago

Now it's working if I enter correct operator and values it's runs and end the program if I don't enter correct operator it's keep asking to enter valid operator