-2

I am trying to make it so that when a random number from 1 to 6 is generated the program will recognise it is an even or an odd number for example if i have a list of odd number and even numbers e.g

even=[2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30];
odd=[1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31];

and the number generated is 3 i want the code to recognise it and print("odd") and same with even.

  • 3
    Are you asking how to check if a number is even or odd, or how to check if a number is in a list (make it a set while you are at it) ? – DeepSpace Sep 16 '19 at 17:43
  • 1
    Possible duplicate of [python - how to check number odd even python?](https://stackoverflow.com/questions/51936179/how-to-check-number-odd-even-python) – Carlos Sep 16 '19 at 17:45

1 Answers1

0

If a number can be devised by 2 then it is even. See the code below:

import random

num = []


def gen_num():
    global num
    for x in range(1):
        num = random.randint(0, 6)

    if (num % 2) == 0:
        print("{} is an Even number".format(num))
    else:
        print("{} is an Odd number".format(num))


gen_num()
Barb
  • 427
  • 3
  • 14