I just want to fetch the first multiple of the input, but my code is showing error.... | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

I just want to fetch the first multiple of the input, but my code is showing error....

PYTHON 3: >>>r=list(range(100)) >>>x=int(input("Enter a number between 1-100:")) >>>for num in r: >>> if num%x==0: >>> print(num) >>>else: print("Not found!") .............................................................. If I a 'break' after print(num), no mater what input I give the process execute and end at '0'.

24th Oct 2019, 5:50 AM
MUGSHOT99
MUGSHOT99 - avatar
1 Answer
+ 3
That's because it stops at the first number in range(100), which is zero. It works of you start the range at 1, e.g. r=list(range(1, 100)) x=int(input("Enter a number between 1-100:")) for num in r: if num%x==0: print(num) quit() else: print("Not found!")
24th Oct 2019, 7:24 AM
David Ashton
David Ashton - avatar