Write program to read 10 random numbers, then find how many of them accept division by 4,
5, and 6.
The program should print the output like this:
There are numbers accept division by 4
There are ------ numbers accept division by 5
There are ------ numbers accept division by 6
Help me guys with this question

Respuesta :

Answer:

In Python:

import random

di4 = 0; di5 = 0; di6 = 0

for i in range(10):

   num = random.randint(1,100)

   if num%4 == 0:

       di4+=1

   if num%5 == 0:

       di5+=1

   if num%6 == 0:

       di6+=1

print("There are "+str(di4)+" numbers accept division by 4")

print("There are "+str(di5)+" numbers accept division by 5")

print("There are "+str(di6)+" numbers accept division by 6")

Explanation:

This imports the random module

import random

This initializes the count of division by 4, 5 or 6 to 0

di4 = 0; di5 = 0; di6 = 0

This iteration is repeated 10 times

for i in range(10):

This generates a random number

   num = random.randint(1,100)

Check if number is divisible by 4. If yes, increase div4 by 1

   if num%4 == 0:

       di4+=1

Check if number is divisible by 5. If yes, increase div5 by 1

   if num%5 == 0:

       di5+=1

Check if number is divisible by 6. If yes, increase div6 by 1

   if num%6 == 0:

       di6+=1

Print reports

print("There are "+str(di4)+" numbers accept division by 4")

print("There are "+str(di5)+" numbers accept division by 5")

print("There are "+str(di6)+" numbers accept division by 6")