Is my code right? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 5

Is my code right?

The programme has to generate a random number which the user has to guess, if the guess is +-5 away from the actual number they will be alerted ”wrong but close” otherwise ”wrong” if the guess is above 100 or below 0 or 1 they will be alerted ”u can only choose between 1-100” https://code.sololearn.com/c0xXLO2pBNTA/?ref=app

26th Jan 2022, 2:29 AM
Lenoname
5 Answers
+ 7
I updated your code as you expected. If you want to ask anything related to this, feel free to ask. https://code.sololearn.com/cgTZ9DmeVpbx/?ref=app
26th Jan 2022, 2:46 AM
Simba
Simba - avatar
+ 3
To avoid negative values. I mean if n = 50; guess = 60, it gives -10 for (n - guess) which is less than 5 and same goes to the next condition.
26th Jan 2022, 3:25 AM
Simba
Simba - avatar
+ 2
Great code Simba! Since 1-100 is a very big set of possible answers it is quite difficult to get the right answer in the first try. Hence I added a loop to it, so that you can keep guessing until you land on the right answer. Here it is: https://code.sololearn.com/cN63K28QlkUa Feel free to ask any questions related to this.
27th Jan 2022, 4:12 PM
Tejas Mestry
+ 1
Simba whats elif 0 <? Not enough with n-guess<=5 or guess-n<=5?
26th Jan 2022, 2:58 AM
Lenoname
0
Tejas Mestry i ran the code and it works but at the end it says something about line 19,what is that?
29th Jan 2022, 8:10 AM
Lenoname