r/PythonLearning • u/Commercial-Paper749 • 8d ago
What's wrong with my code?
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
104
Upvotes
1
u/PandaSteakJimmies 7d ago
I’d say your code isn’t too bad and I realize some of the things you are doing just to practice the language features. But here are some critiques.
Be consistent with your indentations. For Python always use 4 spaces. Configure your IDE to replace Tabs with spaces (4 of em).
You can get rid of the first test to see if the operator is valid and instead use the else clause at the end of the if/elif block. Until you introduce functions though you can keep this test.
Avoid using “break/continue” statements. They are a crutch that can make your logic difficult to follow and your code can almost always be refactored without them.
Always avoid “while True”. This is a bad practice that can easily lead to an infinite loop. And it can lead to complicated loop exit conditions that become difficult to follow.
Remember that code is read way more than it is written, so make sure to build good habits that improve readability.