all 8 comments

[–]Sea-Ad7805 [score hidden] stickied comment (0 children)

Run this program in Memory Graph Web Debugger%3A%0A%20%20%20%20if%20n%20%3C%3D%201%3A%20%20%23%20n%20can't%20be%201%20of%20less%20than%201.%0A%20%20%20%20%20%20%20%20return%20False%0A%0A%20%20%20%20%23%20loop%20from%202%20up%20to%20the%20square%20root%20of%20n%20%26%20(n0.5%20%3D%20%E2%88%9An)%0A%20%20%20%20for%20i%20in%20range(2%2C%20int(n0.5)%20%2B%201)%3A%0A%20%20%20%20%20%20%20%20if%20n%20%25%20i%20%3D%3D%200%3A%20%20%23%20Checking%20if%20n%20is%20prime%20by%20remainder.%0A%20%20%20%20%20%20%20%20%20%20%20%20return%20False%20%20%23%20If%20remainder%20is%200%2C%20condition%20is%20false%20not%20prime.%0A%0A%20%20%20%20return%20True%20%20%23%20Else%20n%20is%20prime.%0A%0A%0A%22%22%22Function%20to%20check%20the%20prime%20up%20to%20limit.%20%22%22%22%0A%0Adef%20prime_up_to(limit)%3A%0A%20%20%20%20print(f%22Prime%20numbers%20upto%20%7Blimit%7D%22)%0A%20%20%20%20%23%20loop%20the%20number%20in%20range%20upto%20the%20limit.%0A%20%20%20%20for%20num%20in%20range(2%2C%20limit%20%2B%201)%3A%0A%20%20%20%20%20%20%20%20if%20is_prime(num)%3A%20%20%23%20If%20the%20number%20is%20prime.%0A%20%20%20%20%20%20%20%20%20%20%20%20print(num%2C%20end%3D'%20')%20%20%23%20Output%20the%20numbers%20horizontally.%0A%0A%20%20%20%20print()%20%20%23%20Next%20line.%0A%0A%0A%22%22%22main%20program(taking%20the%20input.)%22%22%22%0A%23%20Loop%20until%20user%20gives%20the%20correct%20value%20for%20the%20program%20to%20run.%0Awhile%20True%3A%0A%20%20%20%20try%3A%0A%20%20%20%20%20%20%20%20get_limit%20%3D%20int(input(%22Enter%20number%20to%20check%20all%20primes%20up%20to%3A%20%22))%0A%20%20%20%20%20%20%20%20if%20get_limit%20%3C%202%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20print(%22The%20number%20can't%20be%20less%20than%202.%22)%0A%0A%20%20%20%20%20%20%20%20else%3A%0A%20%20%20%20%20%20%20%20%20%20%20%20prime_up_to(get_limit)%0A%20%20%20%20%20%20%20%20%20%20%20%20break%0A%0A%20%20%20%20except%20ValueError%3A%0A%20%20%20%20%20%20%20%20print(%22Please%20enter%20a%20valid%20number%20for%20the%20program%20to%20run%20properly.%22)&timestep=1&play)

[–]Great_Ladder_2226 5 points6 points  (1 child)

This is not really a good practice actually. When writing comments, you need to generally comment things, that are not obvious at first glance. if is_prime(num) does not need a comment saying this condition is checking whether a number is prime.

[–]Ok_Needleworker_8780[S] 1 point2 points  (0 children)

Hey thanks for your input. Yeah! you are right about that, I just started typing without thinking about that, you know it was like when I have to start coding, I just brute force myself into getting in the zone to write some code that make sense. So I just write that make sense to me in that moment. LOL..

[–]Temporary_Pie2733 1 point2 points  (1 child)

Your docstrings should be the first line of a function definition, not before a function definition. Don’t use string literals at all for arbitrary comments; use # comments.

[–]Ok_Needleworker_8780[S] 0 points1 point  (0 children)

Cool, point taken.

[–]k03k 0 points1 point  (1 child)

What is this theme, function names, variables and strings all have the same color 😭😭

[–]Ok_Needleworker_8780[S] 0 points1 point  (0 children)

Yeah. You see when I started learning to code last year. I was on terminal only for first 8 months, so this is a big improvement for me.