Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
hadi mohamadi I just edited my answer and added the code. No problem!
8th Nov 2019, 1:39 PM
Aymane Boukrouh
Aymane Boukrouh - avatar
+ 4
Good, but you can make it better. 1. What is the use of b=2 ? If you're not using it inside the loop, then it's just a waste of memory. Since you're using break statement to stop your loop, it is better to use: while True: # your code here 2. Instead of having to convert 'a' to int everytime you want to use it, simply take it as an input from the first place: a = int(input('Enter a number between 1 and 100: ')) 3. The 3rd elif statement is usless, you're verifying a condition that doesn't matter. If a is not num, and if it is superior than n, then what do you think can it be ? It can only be smaller than n, so checking that condition is a waste of time (small, but can matter in more complex programs), try to use else at the end instead of elif. 4. This is just a new feature, but the walrus expression is definetly useful in this code, if you don't know what that is, check "Walrus python 3.8" in google. Here is a modified version of your code: https://code.sololearn.com/cBsox0fB0k4Q/?ref=app
8th Nov 2019, 1:36 PM
Aymane Boukrouh
Aymane Boukrouh - avatar