Question #3359

Write a program to generate prime numbers, odd numbers and even numbers for a given number. Use different functions for prime numbers, odd numbers and even numbers

Expert's answer

def odd_numbers (number):

return [(x+1) for x in range(number) if (x+1) % 2 == 1]

def even_numbers (number):

return [(x+1) for x in range(number) if (x+1) % 2 == 0]

def prime_numbers (number):

prime = [x+1 for x in range(number)]

for x in range(number-1):

& for y in range(number-1):

& z = (x+2) * (y+2)

& if z > number: break

& if z in prime: prime.remove (z)

return prime

given_number = 18

print (odd_numbers(given_number))

print (even_numbers(given_number))

print (prime_numbers(given_number))

return [(x+1) for x in range(number) if (x+1) % 2 == 1]

def even_numbers (number):

return [(x+1) for x in range(number) if (x+1) % 2 == 0]

def prime_numbers (number):

prime = [x+1 for x in range(number)]

for x in range(number-1):

& for y in range(number-1):

& z = (x+2) * (y+2)

& if z > number: break

& if z in prime: prime.remove (z)

return prime

given_number = 18

print (odd_numbers(given_number))

print (even_numbers(given_number))

print (prime_numbers(given_number))

## Comments

## Leave a comment