vendredi 12 novembre 2021

How to generate random numbers by a certain step?

For school we have to create a program in python in which we generate a given number of random numbers and you can choose by what multiplication. I tried this code (which will show my list is empty) but I'm wondering if there is a specific function for this in python because I cant seem to find out how to do it.

Also, we can't use any other function than randint()

from random import randint

list = []
aantal = int(input("Hoeveel random getallen wilt u? "))
veelvoud = int(input("Welke veelvoud? "))

for i in range(aantal):
    getal = randint(1, 100)
    if getal % veelvoud == 0:
        list.append(getal)
    else:
        i -= 1

print(list)



Aucun commentaire:

Enregistrer un commentaire