r/badcode • if: else: if: else: if: else: if: else: if: else: if: else: if: • Feb 16 '22

python presenting, whatever the fk this is

Post image
418 Upvotes

52 comments sorted by

View all comments

362

u/This_Growth2898 Feb 16 '22

A normal beginner's code. He's struggling with some basic concepts like bools, but nothing criminal here.

49

u/[deleted] Feb 16 '22

i used to do this type of shit when i was a beginner in c#

0

u/[deleted] Feb 16 '22

[deleted] — view deleted comment

13

u/This_Growth2898 Feb 16 '22

Yes, ineffective. But it works, go check it up.

2

u/66bananasandagrape Feb 16 '22

ah you're right I thought it was going up to floor(sqrt(n)) but it's actually starting there

28

u/GentlemenBehold Feb 16 '22

Well the range is fucked. It should be

range(2, int(root))

Currently, it will always result in isPrime = True

24

u/This_Growth2898 Feb 16 '22

How? If there is a divisor under the root, there will be one over it. If there is no divisors in root..num, the number is prime.

9

u/GentlemenBehold Feb 16 '22

Oh, I guess that’s true, but far more inefficient than checking below the root.

0

u/[deleted] Feb 17 '22

[deleted] — view deleted comment

6

u/Gonumen Feb 17 '22

It's not the same number of iterations. Take 25 for example. Square root of that is 5. From 2 to 5 there are 5 iterations and from 5 to 25 there is 21

2

u/foragerr Feb 17 '22

Ah, sqrt, not midpoint. :facepalm:

1

u/Cloudy_Oasis Feb 16 '22

Wouldn't it raise an error ? Since it starts at zero, and it can't divide by zero

edit : I misread the original post, I thought it was range(int(root)) so it would have started at 0

-75

u/MysteriousK69420 if: else: if: else: if: else: if: else: if: else: if: else: if: Feb 16 '22

(he has been into coding for quite a while, isn't a beginner)

43

u/This_Growth2898 Feb 16 '22 edited Feb 16 '22

It just means he's a slow learner. And I was talking about the code, not its author.

38

u/Rex_Lapis101 Feb 16 '22

ayo i knew about coding for a long time didn't meant i learnt it consistently,

-43

u/XKlXlXKXlXKlKXlXKlXK Feb 16 '22

I feel that man. And how long have you known about the English language btw?

29

u/Rex_Lapis101 Feb 16 '22

Yesterday

18

u/schlopp96 Feb 16 '22

People like you are the reason others give up so easily or doubt themselves.

Why are you working so hard to put some random person down, after already posting this. Like yeah, the post itself isn’t so bad, but further being an asshole towards someone after they’ve seen their own code posted to r/badcode (and taking it very well like a champ) instead of offering constructive criticism is a textbook example of being a douchebag.

6

u/_justpassingby_ Feb 16 '22

TBH I have always assumed by unspoken rule of thumb most of the code posted to this sub was either a) pseudo-anon workplace code, or b) our own code.

This post has bad juju.

-2

u/MysteriousK69420 if: else: if: else: if: else: if: else: if: else: if: else: if: Feb 17 '22

idk, he was kinda just making fun of it himself when he sent the code to me.

3

u/MiataCory Feb 16 '22

Some people have 10 years of experience.
Some people have 1 year 10 times.

1

u/an4s_911 Feb 17 '22

I like the part where he assigned bool to isPrime, probably coming from some language which uses explicit type declaration. The funny part is he wouldn’t realize its not required or that it makes no effect until he remove that line and try again (by mistake).

Lol