Sum of numbers divisible by 3 and 5 in python using for loop. This python program with source code is discussed in this post. This python project is useful for beginners and CBSE KV School Class 11 and Class 12 students computer science practical file and NIELIT O Level Programming and Problem Solving through Python ( Module M3-R5).
Write a function Div3and5() that takes a 10 elements numeric tuple and return the sum of elements which are divisible by 3 and 5
Python Program Source Code
Explanation of Code – Sum of numbers divisible by 3 and 5 in python program
def Div3and5(t): #a function named Div3and5(t) is initialized
s=0 #sum variable =0
for i in t: #for loop ends at the length of tupple
if i%3==0 and i%5==0: # checks its divisiblity from 3 and 5
s=s+i # Sum is increased
return s #value is retured from this function
l= # I is an array
for i in range(10):# for loop from i=1 to i=10
print(“Enter the “,i+1,”th number of the tuple”,end=””,sep=””) # asks for input
e=int(input()) # e takes integer input
l.append(e) # adds
t=tuple(l) # creating t tupple to show itself in output with all input numbers
print(“Entered tuple :”,t) #shows the tupple
print(“Sum of numbers in tuple divisible by 3 and 5 =”,Div3and5(t)) # print and calls function Is called Div3and5(t) t is the tupple
Output of Python Program
The below shell window show the input entered (numbers for the tuple). The program execute the command and sum the numbers divisible by 3 and 5.
Testing of program
The input of 10 numbers of tupple, 3 number are divisible by 3,5 . the 3 numbers are 15, 60,45 whose sum is 120.
Source code for the “Sum of numbers divisible by 3 and 5” in python program -> click here
for more python programs -> click here