Issue
But so far I am not getting the output required. I am just a beginner in python.
My code is like this:
import math
import random
from random import randint
for i in range(50):
value = random.randint(1,50)
print(math.floor(value))
Solution
You're doing a few things wrong here, first it's the range, range(50)
allows you to go from 0 to 49, second you always look for random numbers between 1 and 50, finally you don't need the math.floor
since randint
already generates well... int
s, there is a slightly modified version of your script:
import random
from random import randint
for i in range(2, 51):
value = random.randint(1, i)
print(value)
As a side note, you may consider wrapping your code inside a function.
Answered By - RMPR
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.