-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path04_04_exit_loop.py
More file actions
29 lines (25 loc) · 851 Bytes
/
04_04_exit_loop.py
File metadata and controls
29 lines (25 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# write a function that exits a for-loop with a return statement!
"""
input:
list_of_nums: a list of numbers
n: an integer
Returns:
The first number in the list that is divisble by n
Example input: [1,2,3,4,5], 3
output: 3
"""
## Use a for -loop to iterate over the input list
## check if the number is divisble by n with modulo
## if it is -- return the number immediately!
## This will exit the for-loop!!!
from distutils.command.build_scripts import first_line_re
def find_first_divisible(list_of_nums, n):
for i in list_of_nums:
if(i%n==0):
return i
listt=[]
a=int(input("enter the number of elements: "))
for s in range(0,a):
listt.append(int(input()))
divi=int(input("enter the divisor: "))
print(find_first_divisible(listt,divi))