New Course! The Python Programmer Bootcamp with Giles McMullen-Klein
Please let me know what is wrong with the below code. This is 1st quest of practical challenge.
It's working fine if I enter a number between 1-100 in the first go.
However, if I put the number out of this range, it asks to enter a valid number again but doesn't go outside the while loop
num_1 = int(input("Enter first number :"))
num_2 = int(input("Enter second number :"))
while num_1 < 0 or num_2 < 0 or num_1 > 100 or num_2 > 100 or num_1 == num_2:
print("Please enter a valid number")
num1 = int(input("Enter first number :"))
num2 = int(input("Enter second number :"))
if num_1 < num_2:
for i in range(num_1,num_2+1):
print (i, end=' ')
else:
for i in range(num_2,num_1+1):
print (i, end= ' ')
Result :
Enter first number :345
Enter second number :45
Please enter a valid number
Enter first number :34
Enter second number :23
Please enter a valid number
1 answers ( 0 marked as helpful)
Hi Manisha!
Thanks for reaching out!
I executed your code and I got the same error. However, it got fixed after applying the Restart Kernel option. I suggest you to go for Consoles > Restart Kernel and then re-execute the code.
Hope this helps but please feel free to get back to us should you need further assistance.
Best,
The 365 Team