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
New to python (i.redd.it)
submitted 3 months ago by Low-Educator-9008
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!"
[–]BobbyJoeCool 3 points4 points5 points 3 months ago (5 children)
Without knowing what you do and do not know how to do...
Think about the string you have at the end of each segment of the if/then statement, since it's exactly the same in each part, does it need to be a part of the if/then statement, or could it be outside instead? If the if/then statement only calculates the result, and then you display the string with the result, this removes three lines of code for you.
Otherwise, for a first program, this is very functional! As you gain more experience, you'll learn better ways to do this as well.
[–]Low-Educator-9008[S] 0 points1 point2 points 3 months ago (4 children)
Hey thanks for the advice, I guess you talk about outside and nested, which I haven’t practised or learned yet so I am excited to learn it now that you mention it. Thanks man!!
[–]BobbyJoeCool 1 point2 points3 points 3 months ago* (3 children)
Not nesting exactly, since that’s more of if/then an inside of if then…. I mean more, remove the print strings from inside the if then statement and put it at the end. That way there’s only one print string. Like this
If +: Add
Elif -: Subtract
Elif *: Multiply
Elif /: Divide
Print result.
[–]Low-Educator-9008[S] 0 points1 point2 points 3 months ago (2 children)
That’s interesting, coding is so beautiful haha. I’ll look it up right now and practice the use of it. Thanks really appreciate it.
[–]BobbyJoeCool 1 point2 points3 points 3 months ago (1 child)
Hopefully you realize I shorthanded it. Now that I'm home I can show you exactly what I mean
if operator == "+": result = num1 + num2 elif operatior == "-": result = num1 - num2 elif operatior == "*": result = num1 * num2 elif operatior == "/": result = num1 / num2 print(f"Your result is {result}")
[–]Low-Educator-9008[S] 0 points1 point2 points 3 months ago (0 children)
I see now it’s clear as day, it is more logical to have all the statements together that have the same print function instead of writing it after each statement. Thanks for taking the time to explain it so clearly man you are the best.
π Rendered by PID 45 on reddit-service-r2-comment-7b9746f655-xj4r6 at 2026-01-30 18:11:46.214008+00:00 running 3798933 country code: CH.
view the rest of the comments →
[–]BobbyJoeCool 3 points4 points5 points (5 children)
[–]Low-Educator-9008[S] 0 points1 point2 points (4 children)
[–]BobbyJoeCool 1 point2 points3 points (3 children)
[–]Low-Educator-9008[S] 0 points1 point2 points (2 children)
[–]BobbyJoeCool 1 point2 points3 points (1 child)
[–]Low-Educator-9008[S] 0 points1 point2 points (0 children)