Monday 19 September 2022

Example programs in Python: Fibonacci Series

 Writing Fibonacci Series in Python using if else statement and for loop

Example:1

x=int(input("enter the number of terms "))
y=[]

if x==1:
    z=0
    y.append(z)
    print(y)
elif x==2:
    z=0
    q=1
    y.append(z)
    y.append(q)
    print(y)
else:
    z=0
    q=1
    y.append(z)
    y.append(q)
    for i in range(3,x+1):        
        l=y[i-3]
        m=y[i-2]
        k = l + m
        #k=y[i-1]
        y.append(k)
print(y)

Output

enter the number of terms 10
[0, 1, 1, 2, 3, 5, 8, 13, 21, 34]

----------------------------------------------------------------------------------


Example 2: Fibonacci Series

x=int(input("Enter the number of terms: "))
a=0
b=1
print(a,b,end=" ")
for i in range(2,x):
    c = a+b
    print(c,end=" ")
    a=b
    b=c
   
Output

0 1 1 2 3 5 8 13 21 34

Sunday 18 September 2022

Python Example Program: Star Pyramid

 Writing Star Pyramid Program using Function in Python

Example:

x="*"
def function(y):
    i=1
    for i in range(y+1):
        z=i*x
        print(f"{z} ")
function(5)  

Output

* ** *** **** *****

Python Example Program : Palindrome

 Checking whether given word or sequence of number is palindrome

Example 1

word = input("Enter a word to check its palindrome: ")
word=word.lower()
y=len(word)
z=y-1
i=0
while (i<y):
   
    if(word[i]!=word[z]):
        print(f"{word} is not a palindrome")
        break
    i=i+1
    z=z-1    
else:
   
    print(f"{word} is a palindrome")

Output

Enter a word to check its palindrome: Madam
madam is a palindrome

----------------------------------------------------------------------------------

Example 2 : Finding Palindrome in reversing the string

a="mom"
print(f"a= {a}")
b=a[::-1] #it will reverse
print(f"After reversing, b= {b}")
if a==b:
    print(f"{a} is a palindrome")
else:
    print(f"{a} is not a palindrome")

Output

a= mom After reversing, b= mom mom is a palindrome

Python Example Program : Finding Factors

Finding all the possible factors of an integer in Python

Example

x=int(input("Enter a number to find all the possible factors: "))
y=[]
for i in range(1,x+1):
    if x%i == 0:
        y.append(i)
print(y)

Output

Enter a number to find all the possible factors: 400
[1, 2, 4, 5, 8, 10, 16, 20, 25, 40, 50, 80, 100, 200, 400]

Saturday 17 September 2022

Python Example programs : Prime Number

 Finding a number is prime or not in python

Example1

x = int(input("enter a number: "))
i=2
while (i<x):
    if (x%i == 0):
        print(f"{x} is not a prime number")
        break
     
    i=i+1
else:
        print(f"{x} is  a prime number")

Output

enter a number: 7727
7727 is a prime number

-------------------------------------------------------------------------------------


Example 2

x = int(input("enter a  number: "))
i=2
if x <= 0:
       print(f"{x} is not a prime number")
else:
    while (i<x):
        if (x%i == 0):
          print(f"{x} is not a prime number")
          break
     
        i=i+1

    else:
        print(f"{x} is  a prime number")

Output
enter a positive integer number: 0
0 is not a prime number

Python Example Problems : Odd and Even Numbers

 Finding even and odd numbers using while loop in Python

Example 1

i=1
x=[]
y=[]
while (i <= 30):
    if i%2 == 0:
        x.append(i)
       
    else :
        y.append(i)
       
    i = i + 1  
print(f"even numbers are {x} ")    
print(f" odd number are {y} ")

Output

even numbers are [2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28, 30] odd number are [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29]

Example 2

Finding odd and even numbers in a specified list

n = int(input("Enter a number till which we need to list out odd and even numbers: "))
i=1
x=[]
y=[]

while (i <= n):
    if i%2 == 0:
        x.append(i)
       
    else :
        y.append(i)
       
    i = i + 1  
print(f"even numbers are {x} ")    
print(f" odd number are {y} ")

output Enter a number till which we need to list out odd and even numbers: 10
even numbers are [2, 4, 6, 8, 10] odd number are [1, 3, 5, 7, 9]

Monday 6 June 2022

Grade 9 : Math : Word problem on Function

 The function  models the population of rabbits on a farm after   with no removal. The function  models the number of rabbits removed from the population after . Which function,  , models the total number of rabbits on the farm after ?


Solution

f(x) = h(x) + g(x)

that is,

Total models population of rabbits with NO removal = models of rabbits removed from the population after x months + Total number of rabbits on the farm after x months

Let's substitute the given values in the above equation















Hence answer is h(x) = 2(2.0)^x


Saturday 4 June 2022

Grade 9 : Math : Word problem on Linear inequivalities

 A man bought x boxes of doughnuts for $3.49 each, he paid with a $50 bill and received the correct amount of change. If he received more than $10 but less than $20, which inequalities represent the number of boxes of doughnuts he could have bought?

A. 9 ≤ x ≤ 11
B. 8 ≤ x ≤ 12
C. 8 ≤ x ≤ 11
D. 9 ≤ x ≤ 12

Solution

By the given information,

Received amount = total amount paid - x*3.49
                         = 50 - 3.49x

10 ≤ 50 - 3.49x ≤ 20
Hence option A) 9 ≤ x ≤ 11 is the answer.






Math : Grade 9 : Word Problem on Rates

 A pilot flew from airport A to airport B at a rate of 100 km/hr and flew 

back from airport B to airport A at 120 km/hr. The total time it took was 
11 hours. How far is it from airport A to airport B?

Solution

Let's assume, the distance between the airports = d km

Formula : rate = distance / time

airport A to B

        given, rate = 100 km/hr
                  time = t1 (let's assume time take to reach from airport A to B)
                  distance = d

              100 = d/t1   (substitute values in the formula)

airport B to A

   given, rate = 120 km/hr
                  time = t2 (let's assume time take to reach from airport B to A)
                  distance = d
 
                 120 = d/t2  (substitute values in the formula)

also given total time (that is, from airport A to B and airport B to A)= 11 hours

which is      t1+t2 = 11





































Hence, the distance between airports = 600 km



Thursday 2 June 2022

Math : Word problem on Ratios/proportions

Set up and solve the proportions

The park ranger stocks the children's fishing pond, keeping a ratio of 4 sunfish to 3 perch. If he puts 300 sunfish into the pond, how many perch should be put into the pond?

Solution

given, 4Sunfish to 3 perch 

that is 4/3

we have to find 300 Sunfish to how many perch (x)

since its a ratio, we can equate those two












Hence he should put 225perch into the pond

Grade 9 : Word problem on Linear equation

 We can translate word problems into equations to solve

1. Find two consecutive integers whose sum is 45

Solution

let us assume one of the integer is x

since its two consecutive integers, the second integer must be x+1

also given, their sum is 45

that is  x + (x+1) = 45

           2x + 1 =45

              2x = 45 -1 =44

              2x =44

              x = 44/2

              x =22

one of the integer is 22

next integer is 22+1 = 23

let check whether if we add these two integers we will be getting 45

22+23 = 45

hence the two consecutive integers are 22 and 23

Wednesday 1 June 2022

Grade 9 : Math : Word Problem

Water is being pumped into a 10-foot-tall cylindrical tank at a constant rate.

  • The depth of the water is increasing linearly.
  • At 1:30pm, the water depth was 2.4 feet.
  • It is now 4:00pm and the depth of the water is 3.9 feet.

What will the depth (in feet) of the water be at 5:00 pm?

Solution

First lets write the given statement in points ( time, water depth in feet)

Given,

At 1:30pm, the water depth was 2.4 feet

which means (1.5 , 2.4 )

 [ 1.30 pm which means 1 1/2 so, we are writing it as 1.5]

also given, 

It is now 4:00pm and the depth of the water is 3.9 feet.

that is ( 4 , 3.9 )

Now we got two points (x1,y1) = (1.5,2.4)

                                  (x2,y2) = (4,3.9)

Slope (m)= y2 - y1 / x2 - x1

               = 3.9 - 2.4 / 4 - 1.5

               = 1.5 / 2.5

                    m  = 0.60

Every hour water level increases 0.60 feet

we have to find the depth (in feet) of the water be at 5:00 pm

we found m=0.60

lets take one of the given point (1.5,2.4) (x1,y1)

we have to find y when x=5(5pm)

y - y1 = m(x-x1)

y - 2.4 = 0.60(5-1.5)

y - 2.4 = 0.60(3.5)

y-2.4 = 2.1

y = 2.4 + 2.1

    = 4.5 feet

Hence the depth (in feet) of the water be at 5:00 pm is 4.5ft



Tuesday 31 May 2022

Grade 9 : Math : Word Problem

 John mixed cashews and almonds.

 John bought 4 pounds of almonds for a total of $22

The cost per pound for cashews is 60% more than the cost per pound for almonds.

John bought enough cashews that, when he mixed them with the almonds, the mixture had a value of $6.50 per pound.

What percent of the mixture, by weight, were cashews?

a) 20%       b) 25%   c) 30%  d) 35%


Answer

Given


4 Pounds of almonds cost = $22

1 Pound of almonds cost = 22/4 = $5.50

Also given,

 The cost per pound for cashews is 60% more than the cost per pound for almonds

which implies

1 pound of Cashews = 60% of 1pound almonds + cost of 1pound almonds 

                                   = 60% of 5.50 + 5.50

                                   = 0.60 * 5.50 + 5.50

                                   = 3.3 + 5.50

                                   = $ 8.80

 the mixture had a value of $6.50 per pound.

that is, 5.50 almonds + 8.80 Cashews = 6.50

Now, let's take each option one by one and substitute that in the above equation 

a) if cashew is 20% then almond must be 80%

5.50 * 80% + 8.80*20% = 6.50

5.50 * 0.8 + 8.80 * 0.2 = 6.50

     4.4       +  1.76     =  6.50

      6.16  = 6.50 ( Not True )

let's move on to option b)  if cashew is 25% then almond must be 75%

5.50 * 75% + 8.80*25% = 6.50

5.50 * 0.75 + 8.80 * 0.25 = 6.50

    4.125       +  2.2    =  6.50

      6.325  = 6.50 ( Not True )

let's move on to option c)  if cashew is 30% then almond must be 70%

5.50 * 70% + 8.80*30% = 6.50

5.50 * 0.70 + 8.80 * 0.30 = 6.50

    3.85      +  2.64     =  6.50

      6.49  = 6.50 ( which is very close)

let's move on to option d)  if cashew is 35% then almond must be 65%

5.50 * 65% + 8.80*35% = 6.50

5.50 * 0.65 + 8.80 * 0.35 = 6.50

    3.575      +    3.08   =  6.50

      6.655   = 6.50 ( Close but option is more close than this )

Hence the answer is option c) 30%




Tuesday 18 January 2022

Word Problem

Example 

The length of a rectangle is eight less than twice the width. If the perimeter of the rectangle is 122 inches, what are the dimensions of the rectangle?
 
Solution 
 


Word problem on Expression

 Example
 
 Tina took her friend out to eat for lunch. She bought hot dogs that cost x dollars each.They got 4 hot dogs total and Tina paid with a $20 bill.
Write an expression to represent the change that she should receive?
If the hot dogs were $1.50 each, what was Tina’s change? 
 
Solution