Using While condition with Random functions

Hello,

I am trying to use random functio which is mentioned in IoT/ML training of Bolt.

Following is my code:

max=10

min=1

count==0

while count<2:

import random

luckyNumber=random.randint(min,max)

print(luckyNumber)

count=count+1

i am not able to get the desired output which is printing the luckyNumber twice by random. Please let me know how to use while loop in random function.

Hello,
For a loop you need to use indentation to write the body of the loop i.e.

while (condition):
<use multiple spaces or “tab”> (body of the loop)

I hope this helps.
Regards

Hi @himanshumanghani95,

Check the code below -

import random

max=10

min=1

count=0

while count<2:
	luckyNumber=random.randint(min,max)
	print(luckyNumber)
	count=count+1

and the output -

50%20PM

Do let me know in case you need further assitance.

1 Like

@rahul.singh1Yeah It worked.My mistake was count==0. Writing count=0 yields the result ! Hmmm…what is the difference between count==0 and count=o

1 Like

@tunirkv19…I used proper indentation. However in the forum indentation has not mentioned. Neverthless count==0 will not give answer , whereas count=0 will get us the desired result! Thank you

1 Like

Hi @himanshumanghani95,

= is assignment operator it is used to asign values to variables but == is used in comparison.
For example : if 1==1:

2 Likes

@rahul.singh1yes…Thank you ! I studied in college and forgot now ! Bolt forum is awesome…thanks again

1 Like