0% found this document useful (0 votes)
15 views3 pages

Level 011

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views3 pages

Level 011

Uploaded by

RaJu Bhai
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 3

#!

python3

import os
os.system("cls")

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inFactorialValue = int(input("\nPlease Give A Number To Find The Factorial : "))
factValue = 1
print("\nThe Factorial of", inFactorialValue, " is : ", end = "")
while inFactorialValue > 1 :
factValue = factValue * inFactorialValue
inFactorialValue = inFactorialValue - 1

print(factValue, end = "\n")#! python3

import os
os.system("cls")

def findFactorial(inFactorialValue) :
"Function To Find The Factorial Value"
factValue = 1
while inFactorialValue > 1 :
factValue = factValue * inFactorialValue
inFactorialValue = inFactorialValue - 1
return factValue

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inFactorialValue = int(input("\nPlease Give A Number To Find The Factorial : "))
print("\nThe Factorial of", inFactorialValue, " is : ",
findFactorial(inFactorialValue), end = "\n")#! python3

import os
os.system("cls")

def findFactorial(inFactorialValue) :
"Function To Find The Factorial Value"
if inFactorialValue == 0 :
return 1
else :
return inFactorialValue * findFactorial(inFactorialValue - 1)

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inFactorialValue = int(input("\nPlease Give A Number To Find The Factorial : "))
print("\nThe Factorial of", inFactorialValue, " is : ",
findFactorial(inFactorialValue), end = "\n")

Memory Representation
----------------------
factorial(5)
=5*factorial(4)
=5*4*factorial(3)
=5*4*3*factorial(2)
=5*4*3*2*factorial(1)
=5*4*3*2*1
=5*4*3*2
=5*4*6
=5*24
=120#! python3

import os
os.system("cls")

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inSumValue = int(input("\nPlease Give A Number To Find The Sum : "))
sumValue = 1
print("\nThe Sum of", inSumValue, " is : ", end = "")
while inSumValue > 1 :
sumValue = sumValue + inSumValue
inSumValue = inSumValue - 1

print(sumValue, end = "\n")#! python3

import os
os.system("cls")

def findSum(inSumValue) :
"Function To Find The Sum of The Values"
sumValue = 1
while inSumValue > 1 :
sumValue = sumValue + inSumValue
inSumValue = inSumValue - 1
return sumValue

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inSumValue = int(input("\nPlease Give A Number To Find The Sum : "))
print("\nThe Sum of", inSumValue, " Sequential Numbers is : ", findSum(inSumValue),
end = "\n")#! python3

import os
os.system("cls")

def findSum(inSumValue) :
"Function To Find The Sum of The Values"
if inSumValue == 1 :
return 1
else :
return inSumValue + findSum(inSumValue - 1)

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inSumValue = int(input("\nPlease Give A Number To Find The Sum : "))
print("\nThe Sum of", inSumValue, " is : ", findSum(inSumValue), end = "\n")#!
python3

import os
os.system("cls")

def findFactorial(inFactorialValue) :
"Function To Find The Factorial Value"
print("\nFactorial Function Has Been Called With inFactorialValue = " +
str(inFactorialValue), end = "\n")
if inFactorialValue == 0 :
return 1
else :
finalFactValue = inFactorialValue * findFactorial(inFactorialValue - 1)
print("\nIntermediate Result For ", inFactorialValue, " *
findFactorial(", inFactorialValue - 1,"): ", finalFactValue, end = "\n")
return finalFactValue

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inFactorialValue = int(input("\nPlease Give A Number To Find The Factorial : "))
print("\nThe Factorial of", inFactorialValue, " is : ",
findFactorial(inFactorialValue), end = "\n")#! python3

import os
os.system("cls")

def calcSum(inParam) :
"Function To Find The Sum of The Digits of A Number"
finalSum = 0
while(inParam != 0) :
finalSum = finalSum + int(inParam % 10)
inParam = int(inParam / 10)
return finalSum

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inSumValue = int(input("\nPlease Give A Number To Find The Sum of its Digits : "))
print("\nThe Sum of", inSumValue, " is : ", calcSum(inSumValue), end = "\n")#!
python3

import os
os.system("cls")

def calcSum(inParam) :
"Function To Find The Sum of The Digits of A Number"
return 0 if inParam == 0 else int(inParam % 10) + calcSum(int(inParam / 10))

print("\nThis is The Main Module", end = "\n")


print("----------------------------", end = "\n")
inSumValue = int(input("\nPlease Give A Number To Find The Sum of its Digits : "))
print("\nThe Sum of", inSumValue, " is : ", calcSum(inSumValue), end = "\n")

You might also like