Basic Python Programs – 2

#----------------------------- 1 - finding factorial using function ------------------

# factorial of given number
def factorial(number):
	if number < 0:
		print("Factorial cannot be negative.")
	elif number == 0 or number == 1:
		return 1
	else:
		fact = 1
		while(number > 1):
			fact *= number
			number -= 1
		return fact

# Getting the inputs from the user
num = int(input("Enter the number to find the factorial : "))
print("Factorial of",num,"is",factorial(num))

#----------------------------- 2 - finding factorial using recursive function --------

def factorial(num):

	if (num==1 or num==0):
		return 1
	else:
		return num* factorial(num - 1 )  # calling the function n times


# getting and passing the input to function
number = int(input("Enter the number : "))
print ("Factorial of",number,"is",factorial(number))

#----------------------------- 3 - finding simple interest using function --------

# getting principal amount, time and rate of interest from user.


def simpleInterest(princ,year,rate):
	
	S_I = (princ * year * rate)/100  # calculating simple interest
	
	print('The Simple Interest is', S_I)
	
# getting principal amount, time and rate of interest from user.

PA = int(input("Enter the principal amount :"))
Time = int(input("Enter the time period :"))
Rate = int(input("Enter the rate of interest :"))
simpleInterest(PA,Time,Rate)
#----------------------------- 4 - finding compound interest using function --------

# getting principal amount, time and rate of interest from user.


def compoundInterest(principle, rate, year):

	# Calculates compound interest
	total = principle * (pow((1 + rate / 100), year))
	C_I = total - principle
	print("Compound interest is", C_I)



#Taking amount, rate of interest, no. of years  input from user.
principle = int(input("Enter the principal amount: "))
rate = float(input("Enter rate of interest: "))
time = int(input("Enter time in years: " ))
#Function Call
compoundInterest(principle,rate,time)
#----------------------------- 5 - finding compound interest without function --------

principle = int(input("Enter the principal amount: ")) # principal amount 
year= int(input("Enter time in years: " ))	 # time 
rate = float(input("Enter rate of interest: ")) # rate 
# calculates the compound interest
a=principle*(1+(rate/100))**year # formula for calculating amount 
CI=a-principle # compound interest = amount - principal amount
# printing compound interest value
print(CI)
#----------------------------- 6 - finding a number is amstrong or not ---------------

num = int(input("Enter the number : ")) #  getting input from user
ams = num # assigning input value to the s variable
b = len(str(num))
sum1 = 0
# checking amstrong
while num != 0:
	rem = num % 10
	sum1 = sum1+(rem ** b)
	num = num//10
if ams == sum1:
	print("The given number", ams, "is armstrong number")
else:
	print("The given number", ams, "is not armstrong number")

Join our team, where career growth knows no limits.

For More Details

Our internship program guarantees personalized attention for optimal career development in the tech industry.

+91 97879 68375

-> You should bring your own laptop during the internship

Who can apply?

Internships are open for students who: B.E / B.Tech / M.E / M.Tech / B.Sc / M.Sc / M.C.A / B.C.A / Diploma.

  • Ongoing Students Only
  • days, 5days/ 10days or Based on Student Preference
  • Limited 1 to 10 students per slot
  • Registration fees : 1000 INR
  • Slots are filling quickly only fewer slots are available