Skip to main content
Skip to content

Math · Intermediate

Print Prime Numbers 1 to 50 in Hinglish

Find every prime up to 50 with a helper function and jodo.

The program

Edit anything and press Run. The output below was produced by running this exact code.

Expected output

Press Run to try it

Prime numbers 1-50: [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47]Kul 15 prime numbers mile

How it works

kya_prime(n) returns galat for anything below 2, then tries divisors from 2 while d * d <= n. The first divisor it finds proves the number is not prime, so it returns immediately.

The outer loop tests every number from 1 to 50 and uses jodo to add the primes to a list. Printing the list and its lambai gives the 15 primes below 50.