I was trying this random number generator and guessing game in python but it didn't work. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

I was trying this random number generator and guessing game in python but it didn't work.

I guess it happened because we can't import random library in sololearn ,I don't know just guessing. What's your take on this? This is the code import random r= random.randint (1,20) while (True): inp = int (input ()) if(inp<r): print("try typing greater number ") elif(inp>r): print ("try typing smaller number ") else: print("congo you guessed right") break ;

23rd Aug 2020, 7:47 PM
Mr.Stark
Mr.Stark - avatar
3 Answers
+ 3
random works fine on sololearn ,perhaps the loop runs forever ,you need to provide all the inputs first time only
23rd Aug 2020, 7:53 PM
Abhay
Abhay - avatar
+ 2
Limit the number of guesses instead of 'until matching'.. Llke take variable, terminate loop when limit reached i =0 while i < 5 : i += 1 #do next Input 5 numbers and run program...
23rd Aug 2020, 8:25 PM
Jayakrishna 🇮🇳
0
Thanks now it worked
24th Aug 2020, 2:48 AM
Mr.Stark
Mr.Stark - avatar