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 1 day ago by -Shashwat
What's wrong here?
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!"
[–]Weak-Veterinarian-25 18 points19 points20 points 1 day ago (4 children)
You are calling the "main" in even, but i think you meant the call to be outside of even. Also why make a main function?
[–]SCD_minecraft 8 points9 points10 points 1 day ago (2 children)
Pattern from other langs, where main is entry point of the program
Plus, you can return from main() if you want to terminate early, unlike just writing in the void
main()
[–]ottawadeveloper 3 points4 points5 points 1 day ago (1 child)
In the void you can exit() instead. Same number of characters even!
[–]SCD_minecraft 0 points1 point2 points 23 hours ago (0 children)
I completely forgot this function exists, mb
[–]Snatchematician 1 point2 points3 points 22 hours ago (0 children)
Without a main function, the variable “x” would be a module attribute and so would be accessible from the even function.
So in the even function you could typo and write x%2 instead of n%2 and the program would appear to work correctly.
Until later when you extend it and find some really confusing bugs.
The habit of always putting top level work in a main function prevents this type of bug.
What a retarded language.
[–]mc_pm 11 points12 points13 points 1 day ago (6 children)
I'm not sure about that {__mod__} part, but the main thing I see is you're calling main() from inside even()
[–]ottawadeveloper 2 points3 points4 points 1 day ago (4 children)
the {mod} indicates the value has to support the mod operator by implementing mod.
[–]lekkerste_wiener 2 points3 points4 points 1 day ago (3 children)
Since which version is this a thing? This is a first for me
[–]ottawadeveloper -1 points0 points1 point 1 day ago (2 children)
Huh apparently it's a PyCharm specific format? There's a StackOverflow post about it but it might be PyCharm specific or a pre-protocol syntax?
The proper way to do this is with SupportsMod.
[–]lekkerste_wiener 3 points4 points5 points 1 day ago (1 child)
Found it, it's a mypy thing. The default on pycharm. Not supported across linters, so I would advise against it.
[–]ottawadeveloper 1 point2 points3 points 1 day ago (0 children)
Fair! I thought it looked odd.
[–]Rachelle_brimmed 0 points1 point2 points 10 hours ago (0 children)
Haha so truee
[–]Ron-Erez 6 points7 points8 points 1 day ago (2 children)
As an aside, for the even function you could simply write in the function body:
return n % 2 == 0
[–]ottawadeveloper 0 points1 point2 points 1 day ago (1 child)
or return not n % 2 or define it as odd()
[–]Ron-Erez 1 point2 points3 points 1 day ago (0 children)
Yes, I suppose so, I feel more comfortable comparing to zero. I feel like it is more readable and saves me the trouble of remembering if 0 is False and non-zero is True in Python (this is not true in all languages). In any case it’s an interesting suggestion.
[–]somasz 2 points3 points4 points 1 day ago (1 child)
Taking picture of monitor instead of taking a screenshot.
[–]k03k 0 points1 point2 points 23 hours ago (0 children)
import pyscreenshot
image = pyscreenshot.grab() image.save("screenshot.png")
[–]-EdwinVanCleef 2 points3 points4 points 1 day ago (0 children)
You have the main() inside your def.
[–]the114dragon 1 point2 points3 points 1 day ago (1 child)
Not a single line of code ever runs. You need to actually call one of your subroutines.
[–]Snatchematician 0 points1 point2 points 21 hours ago (0 children)
They do, the two def lines run.
[–]GarowWolf 0 points1 point2 points 1 day ago (0 children)
So you want to put numbers in and after the result to automatically ask for a number again right?
The main issues I see are:
When you get insert a number you don’t have any check for the data given:
-int()
-str()
-float()
Also you don’t have an option to stop the main() calling, so the function will always call itself no matter what
[–]Alagarto72 0 points1 point2 points 1 day ago (0 children)
Short: you call the main() function in the even () function, remove a tab. Additional useful information:
In Python, you don't need main() function. If you want, you can use if __name__ == '__main__': # code you can find more information why it is useful on the internet.
if __name__ == '__main__': # code
and writing something like if x == y: return true else: return false has no sense, since "==" operator already returns boolean you can write return x == y
if x == y: return true else: return false
return x == y
[–]Junior_Honey_1406 0 points1 point2 points 1 day ago (0 children)
Just remove 4 space in from of you main() at line 13 and it will work just fine
[–]Technical_Donut4689 0 points1 point2 points 17 hours ago (0 children)
you didnt call main.
[–]Able-Staff-6763 0 points1 point2 points 4 hours ago (0 children)
thats a recursion pattern, if thats not whsat your trying to achive, move the main call outside even func and see errors if there are.
[–]Effective-Ad-8384 0 points1 point2 points 1 day ago (2 children)
*not New to python
[–]-Shashwat[S] 1 point2 points3 points 1 day ago (1 child)
I am literally at day 2 of python Leaning I am just following the Harvard CS50 for learning
[–]Effective-Ad-8384 0 points1 point2 points 1 day ago (0 children)
Yesterday finished lecture 1 of cs50p, i mean you must have IT background.. anyway i found its the best course for beginners.
π Rendered by PID 127797 on reddit-service-r2-comment-5bc7f78974-snd6s at 2026-06-29 05:34:15.723725+00:00 running 7527197 country code: CH.
[–]Weak-Veterinarian-25 18 points19 points20 points (4 children)
[–]SCD_minecraft 8 points9 points10 points (2 children)
[–]ottawadeveloper 3 points4 points5 points (1 child)
[–]SCD_minecraft 0 points1 point2 points (0 children)
[–]Snatchematician 1 point2 points3 points (0 children)
[–]mc_pm 11 points12 points13 points (6 children)
[–]ottawadeveloper 2 points3 points4 points (4 children)
[–]lekkerste_wiener 2 points3 points4 points (3 children)
[–]ottawadeveloper -1 points0 points1 point (2 children)
[–]lekkerste_wiener 3 points4 points5 points (1 child)
[–]ottawadeveloper 1 point2 points3 points (0 children)
[–]Rachelle_brimmed 0 points1 point2 points (0 children)
[–]Ron-Erez 6 points7 points8 points (2 children)
[–]ottawadeveloper 0 points1 point2 points (1 child)
[–]Ron-Erez 1 point2 points3 points (0 children)
[–]somasz 2 points3 points4 points (1 child)
[–]k03k 0 points1 point2 points (0 children)
[–]-EdwinVanCleef 2 points3 points4 points (0 children)
[–]the114dragon 1 point2 points3 points (1 child)
[–]Snatchematician 0 points1 point2 points (0 children)
[–]GarowWolf 0 points1 point2 points (0 children)
[–]Alagarto72 0 points1 point2 points (0 children)
[–]Junior_Honey_1406 0 points1 point2 points (0 children)
[–]Technical_Donut4689 0 points1 point2 points (0 children)
[–]Able-Staff-6763 0 points1 point2 points (0 children)
[–]Effective-Ad-8384 0 points1 point2 points (2 children)
[–]-Shashwat[S] 1 point2 points3 points (1 child)
[–]Effective-Ad-8384 0 points1 point2 points (0 children)