0

Help need for repeat task(solved)

import random A = [10,20,30,40,50,60] random.shuffle(A) X = (A[0] / 10) if X > 2: print("Ok" ,X) else: print("Not Ok", X) # How i get always > 2.0 in this code Dont want to print Not Ok #EDIT SOLVED #It will give always print Ok import random A = [10,20,30,40,50,60] random.shuffle(A) X = (A[0] / 10) if X >= 3: print("Ok" ,X) else: print("Not Ok and Retrying....") X = (A[1] / 10) if X >= 3: print("Ok" ,X) else: print("Not Ok and Retrying....") X = (A[2] / 10) if X >= 3: print("Ok" ,X)

27th Mar 2020, 1:52 PM
ғᴜɴ 3x
ғᴜɴ 3x - avatar
5 Réponses
+ 1
Why? May I what exactly you are trying here? Edit: ғᴜɴ 3x import random A = [10,20,30,40,50,60] while True: random.shuffle(A) X = (A[0] / 10) if X > 2: print("Ok" ,X) break #2nd way import random A = [10,20,30,40,50,60] random.shuffle(A) i=0 while True : X = (A[i] / 10) if X >= 3: print("Ok" ,X) break else: print("Not Ok and Retrying....") i++
27th Mar 2020, 2:07 PM
Jayakrishna 🇮🇳
+ 1
You can do it more ways.. ғᴜɴ 3x Put X=A[0] only.. Instead A[0]/10 //OK? But still it is not clear... Edit : Is you want to print otherthan 10 and 20 from list....?
27th Mar 2020, 2:12 PM
Jayakrishna 🇮🇳
0
Want to give me ans only 2 or up
27th Mar 2020, 2:08 PM
ғᴜɴ 3x
ғᴜɴ 3x - avatar
0
After random.suffle(A) please add print(A). Your code is working but you have a probability of 1/6 to output Not Ok. Do it ten times import random A = [10,20,30,40,50,60] for i in range(10): random.shuffle(A) print(A) X = (A[0]/10) if X > 2: print("Ok" ,X) else: print("Not Ok", X)
27th Mar 2020, 2:09 PM
Elhadji Mama GUENE
Elhadji Mama GUENE - avatar
0
Jayakrishna🇮🇳 Thanks A Lot Bro 👌👏👏 I like first one while loop 👌
27th Mar 2020, 3:53 PM
ғᴜɴ 3x
ғᴜɴ 3x - avatar