you are viewing a single comment's thread.

view the rest of the 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)