Python programs
1) Write a program to enter two numbers and perform all arithmetic
operations
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
sum=a+b
diff=a-b
mul=a*b
div=a/b
mod=a%b
print("sum=",sum, "diff=",diff, "mul=",mul, "div=",div, "mod=",mod)
Output:
Enter the first number:20
Enter the second number:40
sum= 60 diff= -20 mul= 800 div= 0.5 mod= 20
2) Write a program to check divisibility of a number with another number
a=int(input("Enter the first number:"))
b=int(input("Enter the second number:"))
remainder=a%b
if remainder==0:
print(a,"is divisible by",b)
else:
print(a,"is not divisible by",b)
Output:
Enter the first number:90
Enter the second number:30
90 is divisible by 30
3) Write a program to calculate simple interest and compound interest
p=int(input("Enter the first number:"))
r=int(input("Enter the second number:"))
t=int(input("Enter the third number:"))
si=(p*r*t)/100
ci=p*(pow((1+(r/100)),t))
print("Principal amount:",p)
print("Rate of interest:",r)
print("Time in years:",t)
print("Simple interest:",si)
print("Compound interest:",ci)
Output:
Enter the first number:20000
Enter the second number:20
Enter the third number:2
Principal amount: 20000
Rate of interest: 20
Time in years: 2
Simple interest: 8000.0
Compound interest: 28800.0
4) Write a program to demonstrate accessing an element from a list
and modifying in a list
list=[10,20,30,40,50]
print(list)
list[1]=4
print(list)
Output:
[10, 20, 30, 40, 50]
[10, 4, 30, 40, 50]