Is my code right? | Sololearn: Learn to code for FREE!


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”

1/26/2022 2:29:22 AM


5 Answers

New Answer


I updated your code as you expected. If you want to ask anything related to this, feel free to ask.


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.


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: Feel free to ask any questions related to this.


Simba whats elif 0 <? Not enough with n-guess<=5 or guess-n<=5?


Tejas Mestry i ran the code and it works but at the end it says something about line 19,what is that?