How to make generator to produce N prime number?

def is_prime(num):

    for n in range(2, num):

        if num % n == 0:

            return False

    return True


# using Generator(Yield)

def generate_n_prime(num):

    i = 2

    while num:

        if is_prime(i):

           yield i

         num -= 1

      i += 1


it = generate_n_prime(10)

for i in it:

    print(i, end=' ')


#2 3 5 7 11 13 17 19 23 29

View More...

Write Python Program for N prime number?

def is_prime(num):

   for n in range(2, num):

        if num % n == 0:

           return False

    return True

def get_n_prime(num):

   i = 2

   prime_list = []

   while num:

      if is_prime(i):

         prime_list.append(i)

         num -= 1

      i += 1

   return prime_list


print(get_n_prime(10))

#[2, 3, 5, 7, 11, 13, 17, 19, 23, 29]

View More...

List Of All Python Exception Classes

The class hierarchy for built-in exceptions is:

BaseException

 +-- SystemExit

 +-- KeyboardInterrupt

 +-- GeneratorExit

 +-- Exception( All given below Exception class are childs of Exception Class)

    +-- StopIteration

    +-- StopAsyncIteration

    +-- ArithmeticError

    |    +-- FloatingPointError  (Not currently used.)

    |    +-- OverflowError

    |    +-- ZeroDivisionError

   +-- AssertionError

   +-- AttributeError

  +-- BufferError

  +-- EOFError

  +-- ImportError

  |    +-- ModuleNotFoundError

  +-- LookupError

  |    +-- IndexError

  |    +-- KeyError

  +-- MemoryError

  +-- NameError

  |    +-- UnboundLocalError

  +-- OSError

  |    +-- BlockingIOError

  |    +-- ChildProcessError

  |    +-- ConnectionError

  |    |     +-- BrokenPipeError

  |    |     +-- ConnectionAbortedError

  |    |     +-- ConnectionRefusedError

  |    |    +-- ConnectionResetError

  |    +-- FileExistsError

  |    +-- FileNotFoundError

  |   +-- InterruptedError

  |   +-- IsADirectoryError

  |   +-- NotADirectoryError

  |   +-- PermissionError

  |   +-- ProcessLookupError

  |   +-- TimeoutError

 +-- ReferenceError

 +-- RuntimeError

 |    +-- NotImplementedError

 |    +-- RecursionError

 +-- SyntaxError

 |    +-- IndentationError

 |    +-- TabError

 +-- SystemError

 +-- TypeError

 +-- ValueError

  |    +-- UnicodeError

  |    +-- UnicodeDecodeError

  |    +-- UnicodeEncodeError

  |    +-- UnicodeTranslateError

   +-- Warning

     +-- DeprecationWarning

     +-- PendingDeprecationWarning

     +-- RuntimeWarning

     +-- SyntaxWarning

     +-- UserWarning

     +-- FutureWarning

     +-- ImportWarning

     +-- UnicodeWarning

     +-- BytesWarning

    +-- ResourceWarning

View More...

pip2 install using curl

sudo apt update

sudo apt upgrade

sudo add-apt-repository universe

>sudo apt install python2

>sudo apt install curl

>curl https://bootstrap.pypa.io/get-pip.py --output get-pip.py

>sudo apt install python3-pip

View More...

How can Change/Reset Repository

Check Remote Connection

> git remote -v

output similar to the following:

origin https://github.com/user1/oldrepo.git (fetch)

origin https://github.com/user1/oldrepo.git (push)

Set New Repo

>git remote set-url origin https://github.com/user2/newrepo.git

Again Check Remote Connection

>git remote -v

origin https://github.com/user2/newrepo.git (fetch)

origin https://github.com/user2/newrepo.git (push)

View More...

First Previous 2 3 4 5 6 Next Last