Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Friday, 12 January 2018

Python Program to Find Those Numbers which are Divisible by 7 and Multiple of 5 in a Given Range of Numbers

Source Code :

lower= int (input("Enter the lower limit :"))
upper= int (input("Enter the upper limit :"))
for i in range(lower,upper+1):
    if(i%7==0 and i%5==0):
        print(i)

    
Output :

Enter the lower limit :100
Enter the upper limit :400
105
140
175
210
245
280
315
350
385

Python Program to Print Largest Even and Largest Odd Number in a List

Source Code :

n = int(input("Enter the no of elements in the list :"))
b=[]
for i in range(0,n):
    a=int(input("Enter elements :"))
    b.append(a)
c=[]
d=[]

for i in b:
    if (i%2==0):
        c.append(i)
    else :
        d.append(i)
c.sort()
d.sort()
count1=0
count2=0
for k in c:
    count1=count1+1
for j in d:
    count2=count2+1
print("Largest even no is : ",c[count1-1])

print("Largest odd no is :", d[count2-1])

Output :

Enter the no of elements in the list :7
Enter elements : 9
Enter elements : 17
Enter elements : 2
Enter elements : 89
Enter elements : 40
Enter elements : 102
Enter elements : 101
Largest even no is :  102
Largest odd no is : 101

Python Program to Print Sum of Negative Numbers, Positive Even Numbers and Positive Odd numbers in a List

Source Code :

n=int(input("Enter the no of elemnets in the list"))
b=[]
for i in range(0,n):
    a=int(input("Elements :"))
    b.append(a)
sum1=0
sum2=0
sum3=0

for j in b :
    if(j>0):
        if(j%2==0):
            sum1=sum1+j
        else :
            sum2=sum2 + j
    else :
        sum3=sum3+j
print("Sum of all positive even no :",sum1)
print("Sum of all positive odd no ",sum2)

print("Sum of all negative no", sum3)

Output :

Enter the no of elements in the list 7
Elements :1
Elements :4
Elements :-6
Elements : -1
Elements : 8
Elements : 1
Elements :9
Sum of all positive even no : 12
Sum of all positive odd no  11

Sum of all negative no -7


Python Program to Compute Simple Interest Given all the Required Values :

Program/Source Code :


n=int(input("Enter the number to print the tables for:"))
for i in range(1,11):
    print(n,"x",i,"=",n*i)

Output :

Enter the no :7
7 X 1 = 7
7 X 2 = 14
7 X 3 = 21
7 X 4 = 28
7 X 5 = 35
7 X 6 = 42
7 X 7 = 49
7 X 8 = 56
7 X 9 = 63
7 X 10 = 70



Python Program to Compute Simple Interest Given all the Required Values :

Program/Source Code :


principle=float(input("Enter the p amount:"))
time=int(input("Enter the time(years) :"))
rate=float(input("Enter the rate :"))
simple_interest=(principle*time*rate)/100
print("the simple interest is :",simple_interest)


Output:


case 1:

Enter the p amount:1200
Enter the time(years) :4
Enter the rate :2
the simle interest is : 96.0


case 2:

Enter the p amount:200
Enter the time(years) :5
Enter the rate :5

the simle interest is : 50.0