*1. Python3 program to add two numbers*
num1 = 15
num2 = 12
# Adding two nos
sum = num1 + num2
# printing values
print("Sum of {0} and {1} is {2}" .format(num1, num2, sum))
@python_0
num1 = 15
num2 = 12
# Adding two nos
sum = num1 + num2
# printing values
print("Sum of {0} and {1} is {2}" .format(num1, num2, sum))
@python_0
2. program to find simple interest for given principal amount, time and rate of interest.
# We can change values here for
# different inputs
P = int(input())
R = int(input())
T = int(input())
# Calculates simple interest
SI = (P * R * T) / 100
# Print the resultant value of SI
print("simple interest is", SI)
@python_0
# We can change values here for
# different inputs
P = int(input())
R = int(input())
T = int(input())
# Calculates simple interest
SI = (P * R * T) / 100
# Print the resultant value of SI
print("simple interest is", SI)
@python_0
3.Find the factorial of given number
def factorial(n):
if n < 0:
return 0
elif n == 0 or n == 1:
return 1
else:
fact = 1
while(n > 1):
fact *= n
n -= 1
return fact
num = 5;
print("Factorial of",num,"is",
factorial(num))
@python_0
def factorial(n):
if n < 0:
return 0
elif n == 0 or n == 1:
return 1
else:
fact = 1
while(n > 1):
fact *= n
n -= 1
return fact
num = 5;
print("Factorial of",num,"is",
factorial(num))
@python_0
4.Program to find sum of square of first n natural numbers
def squaresum(n) :
sm = 0
for i in range(1, n+1) :
sm = sm + (i * i)
return sm
n = 4
print(squaresum(n))
@python_0
def squaresum(n) :
sm = 0
for i in range(1, n+1) :
sm = sm + (i * i)
return sm
n = 4
print(squaresum(n))
@python_0
5.Write a Python program to sum of all digits of a number
n=int(input("Enter a number:"))
sum=0
while n>0:
rem=n%10
sum=sum+rem
n=int(n/10)
print("The sum of digits of number is:", sum)
@python_0
n=int(input("Enter a number:"))
sum=0
while n>0:
rem=n%10
sum=sum+rem
n=int(n/10)
print("The sum of digits of number is:", sum)
@python_0
