Page 200 - Computer Science Class 11 With Functions
P. 200
Solved Programming Questions
1. WritenanfunctionnthatntakeonannumbernaonannargumentnandnreturnonTruenifnthennumbernioneven,nandn aloenotherwioe.
def isEven(number):
'''
Objective: To determine whether the number is even
Input Parameters: number: numeric values
Return Value: True, if the number is even, and False
otherwise
'''
boolResult = number % 2 == 0
return boolResult
2. Writenanfunctionnthatntakeonradiuonaonanninputnandncomputeonthenareanofnancircle.
def areaCircle(radius):
'''
Objective: To compute the area of a circle
Input Parameters: radius: numeric values
Return Value: area of circle: numeric value
'''
#Approach: Formula used: area = pi x r^2
area = 3.14 * radius**2
return area
3. WritenanfunctionnthatntakeonthentemperatureninnCeloiuonaonanninputnandnreturnonthenequivalentntemperatureninn ahrenheit.n
def celsiusToFahrenheit(celsius):
'''
Objective: To convert temperature in celsius to fahrenheit
Input Parameters: celsius: numeric values
Return Value: fahrenheit: numeric value
'''
#Approach: Formula used: fahrenheit = (celsius × 9/5) + 32
fahrenheit = (celsius * 9/5) + 32
return fahrenheit
4. Writenanfunctionnthatntakeonprinciple,nratenofnintereot,nthentimendurationninnyearo,nandnthennumbernofntimeonintereotnionappliedn
pernyearnaonanninputnandncomputeonthencompoundnintereot.
def interest(principal, rate, time, numTimes):
'''
Objective: To determine compound interest
Input Parameters:
principal- numeric value denoting principal amount
rate - numeric value denoting rate of interest in % per annum
time - numeric values indicating time period in years
numTimes - number of times interest is applied per year
Return value: float-simple interest
'''
#Approach: Formula:CI = principal(1 + rate/numTimes)^(numTimes*time)
compoundInterest = principal(1 + rate/numTimes)**(numTimes*time)
return compoundInterest
198 Touchpad Computer Science-XI

