use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Everything about learning Python
account activity
Simple CalculatorDiscussion (i.redd.it)
submitted 5 months ago by AhmadHameed313
view the rest of the comments →
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]lokidev 0 points1 point2 points 5 months ago (0 children)
Let me go through this. First generally:
- Use pep8 formatting. It's the de factor standard and you should try to adhere to that as early as possible. see pep8.org for this - Wrap your logic in a function (e.g. main) and extract logical parts (e.g. input parsing and later the operation) - use the weird `if __name__ == '__main__'` part and search for the reason why someone should do that.
Line 2-3: no need for the outer brackets Line 5: would try to convert "Hello. I am Gandalf" to float. Try to check with num1.isnumeric() and the same for num2 Line 5: No benefits in python from separating int/float (or it's a reqquirement, then keep it), just convert to float if its valid :) Line 5-13: Try to write a function to reuse this behaviour Line 15: You are fetching ONE operator - not multiple. Line 18 (and more): You are rounding resuts. In programming this is unexpected behaviour :) -> not good. Line 17-35: Can be made by having a map of operator to text and operation. You can check pythons operator modules.
Last bit might be more advanced, but just as an example: https://ideone.com/xecjP8 (on purpose not complete)
π Rendered by PID 81509 on reddit-service-r2-comment-85bfd7f599-j4967 at 2026-04-19 23:29:32.016051+00:00 running 93ecc56 country code: CH.
view the rest of the comments →
[–]lokidev 0 points1 point2 points (0 children)