Home > Software engineering >  Python Program to Check if a Number is Odd or Even
Python Program to Check if a Number is Odd or Even

Time:11-26

Im very new to this. I just started programming last week. I need some basic help. My assignment is to write five integral number and get the output to print out "odd" or "even". This is how I have started.

num = int(input())
if (num % 2) == 0:  
  print ('even')
else:
  print ('odd')

How can I have five random number in the input. I dont want to make a list, the program has to work with different numbers each time. I hope you understand my question. Thank you for helping out.

CodePudding user response:

Try this:

import random
for i in range(5):
    num = random.randint(1, 10)
    if num % 2 == 0:
        print('even')
    else:
        print('odd')

CodePudding user response:

Hi

  • Related