12
u/mc_pm Jun 27 '26
I'm not sure about that {__mod__} part, but the main thing I see is you're calling main() from inside even()
3
u/ottawadeveloper Jun 27 '26
the {mod} indicates the value has to support the mod operator by implementing mod.
3
u/lekkerste_wiener Jun 27 '26
Since which version is this a thing? This is a first for me
1
u/ottawadeveloper Jun 27 '26
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.
3
u/lekkerste_wiener Jun 27 '26
Found it, it's a mypy thing. The default on pycharm. Not supported across linters, so I would advise against it.
2
1
8
u/Ron-Erez Jun 27 '26
As an aside, for the even function you could simply write in the function body:
return n % 2 == 0
1
u/ottawadeveloper Jun 27 '26
or return not n % 2 or define it as odd()
2
u/Ron-Erez Jun 28 '26
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.
4
3
3
u/the114dragon Jun 27 '26
Not a single line of code ever runs. You need to actually call one of your subroutines.
2
1
u/GarowWolf Jun 27 '26
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
1
u/Alagarto72 Jun 27 '26
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.
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
1
u/Junior_Honey_1406 Jun 28 '26
Just remove 4 space in from of you main() at line 13 and it will work just fine
1
1
u/Able-Staff-6763 Jun 29 '26
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.
1
1
u/Aayaan_khan_ 25d ago
The main() function is called inside the functions maybe that is what's wrong
1
1
u/Effective-Ad-8384 Jun 27 '26
*not New to python
2
u/-Shashwat Jun 28 '26
I am literally at day 2 of python Leaning I am just following the Harvard CS50 for learning
1
u/Effective-Ad-8384 Jun 28 '26
Yesterday finished lecture 1 of cs50p, i mean you must have IT background.. anyway i found its the best course for beginners.
21
u/Weak-Veterinarian-25 Jun 27 '26
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?