+ 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'.
1 Réponse
+ 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!")