The 365 Data Science team is proud to invite you to our own community forum. A very well built system to support your queries, questions and give the chance to show your knowledge and help others in their path of becoming Data Science specialists.
Ask
Anybody can ask a question
Answer
Anybody can answer
Vote
The best answers are voted up and moderated by our team

New Course! The Python Programmer Bootcamp with Giles McMullen-Klein

New Course! The Python Programmer Bootcamp with Giles McMullen-Klein

Super Learner
0
Votes
0
Answer

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

No answers so far.
×
Online Data Science Training
SAVE 60%