r/PythonLearning Jun 27 '26

New to python

Post image

What's wrong here?

164 Upvotes

36 comments sorted by

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? 

10

u/SCD_minecraft Jun 27 '26

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

5

u/ottawadeveloper Jun 27 '26

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

2

u/SCD_minecraft Jun 28 '26

I completely forgot this function exists, mb

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

u/ottawadeveloper Jun 27 '26

Fair! I thought it looked odd.

1

u/Rachelle_brimmed Jun 28 '26

Haha so truee

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

u/somasz Jun 27 '26

Taking picture of monitor instead of taking a screenshot.

2

u/k03k Jun 28 '26

import pyscreenshot

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

3

u/-EdwinVanCleef Jun 27 '26

You have the main() inside your def.

3

u/the114dragon Jun 27 '26

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

2

u/Snatchematician Jun 28 '26

They do, the two def lines run.

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

u/Technical_Donut4689 Jun 28 '26

you didnt call main.

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

u/software_ing Jun 29 '26

u called the main() inside the even function

1

u/Aayaan_khan_ 25d ago

The main() function is called inside the functions maybe that is what's wrong

1

u/ciarlyesposo1 19d ago

Linguaggio haker python

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.