I am trying to make a function that generates a random number from 0 to max (including the max) repeatedly num times. The function returns the count of how many numbers are less than the limit. I am wondering stuck on how to get the limit value to print at the end of the random numbers.
b = 0
def howManyLessThan(maX,num,limit):
for i in range(num):
x = random.randrange(0,maX+1)
print(x)
if x < limit:
b+1
elif x>limit:
b+0
howManyLessThan(6, 10, 5)
print(b)
>Solution :
- Your indentation is incorrect. The if and elif have to be inside the for-loop so indent them one more level.
- Check the basic syntax on how to change a variable.
b+1does not do anything.b += 1increases b by 1. - Rather than using a global variable b,
return bfrom your function, once the loop is complete.