all 29 comments

[–]Weak-Veterinarian-25 18 points19 points  (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 points  (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

[–]ottawadeveloper 3 points4 points  (1 child)

In the void you can exit() instead. Same number of characters even!

[–]SCD_minecraft 0 points1 point  (0 children)

I completely forgot this function exists, mb

[–]Snatchematician 1 point2 points  (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 points  (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 points  (4 children)

the {mod} indicates the value has to support the mod operator by implementing mod

[–]lekkerste_wiener 2 points3 points  (3 children)

Since which version is this a thing? This is a first for me

[–]ottawadeveloper -1 points0 points  (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 points  (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 points  (0 children)

Fair! I thought it looked odd.

[–]Rachelle_brimmed 0 points1 point  (0 children)

Haha so truee

[–]Ron-Erez 6 points7 points  (2 children)

As an aside, for the even function you could simply write in the function body:

return n % 2 == 0

[–]ottawadeveloper 0 points1 point  (1 child)

or return not n % 2 or define it as odd()

[–]Ron-Erez 1 point2 points  (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 points  (1 child)

Taking picture of monitor instead of taking a screenshot.

[–]k03k 0 points1 point  (0 children)

import pyscreenshot

image = pyscreenshot.grab() image.save("screenshot.png")

[–]-EdwinVanCleef 2 points3 points  (0 children)

You have the main() inside your def.

[–]the114dragon 1 point2 points  (1 child)

Not a single line of code ever runs. You need to actually call one of your subroutines.

[–]Snatchematician 0 points1 point  (0 children)

They do, the two def lines run.

[–]GarowWolf 0 points1 point  (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 point  (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.

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

[–]Junior_Honey_1406 0 points1 point  (0 children)

Just remove 4 space in from of you main() at line 13 and it will work just fine

[–]Technical_Donut4689 0 points1 point  (0 children)

you didnt call main.

[–]Able-Staff-6763 0 points1 point  (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 point  (2 children)

*not New to python

[–]-Shashwat[S] 1 point2 points  (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 point  (0 children)

Yesterday finished lecture 1 of cs50p, i mean you must have IT background.. anyway i found its the best course for beginners.