File tree Expand file tree Collapse file tree
math/Prime-Number-Analyzer Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88 print ("2. Generate prime numbers up to N" )
99 print ("3. Find primes in a range" )
1010 print ("4. Prime factorization" )
11- print ("5. Exit" )
12-
13- choice = input ("\n Enter your choice (1-5): " )
14-
11+ print ("5. Find the Nth prime number" )
12+ print ("6. Exit" )
13+
14+ choice = input ("\n Enter your choice (1-6): " )
15+
1516 if choice == '1' :
1617 print ("\n " + "-" * 50 )
1718 print ("CHECK IF A NUMBER IS PRIME" )
157158 print ("Please enter a valid number!" )
158159
159160 elif choice == '5' :
161+ print ("\n " + "-" * 50 )
162+ print ("FIND THE NTH PRIME NUMBER" )
163+ print ("-" * 50 )
164+
165+ try :
166+ n = int (input ("Enter the value of n: " ))
167+
168+ if n <= 0 :
169+ print ("\n Please enter a positive number!" )
170+ else :
171+ count = 0
172+ num = 1
173+
174+ while count < n :
175+ num += 1
176+ is_prime = True
177+ divisor = 2
178+
179+ while divisor * divisor <= num :
180+ if num % divisor == 0 :
181+ is_prime = False
182+ break
183+ divisor += 1
184+
185+ if is_prime :
186+ count += 1
187+
188+ print (f"\n The { n } th prime number is: { num } " )
189+
190+ except ValueError :
191+ print ("Please enter a valid number!" )
192+
193+ elif choice == '6' :
160194 print ("\n " + "=" * 50 )
161195 print ("Thank you for using Prime Number Analyzer!" )
162196 print ("=" * 50 )
163197 break
164198
165199 else :
166- print ("\n Invalid choice! Please enter a number between 1 and 5 ." )
200+ print ("\n Invalid choice! Please enter a number between 1 and 6 ." )
167201
168202 print ("\n " + "=" * 50 )
You can’t perform that action at this time.
0 commit comments