Esempio n. 1
0
    #returns n-th term of geometric sequence starting with element a1 and having
    value = a1 * pow(factor, index - 1)
    return value


def GiveFactorForGeomSeq(term, nextterm):
    #returns factor for geometrical sequence having two following terms of the sequence
    return nextterm / term


def GiveSumOfNElementsGeomSeq(a1=2, factor=2, n=2):
    #returns sum of n first elements of geometrical sequence with first term a1 and factor
    sumN = a1 * (1 - pow(factor, n)) / (1 - factor)
    return sumN


import geom

print('2^64 =', geom.GiveGeomSeqElement(1, 2, 64))
print('------------------------------------------------')
a1 = 3
factor = 2
maxindex = 11
for i in range(1, maxindex + 1):
    an = geom.GiveGeomSeqElement(a1=a1, factor=factor, index=i)
    print('Term ', i, '=', an)
print('------------------------------------------------')
print('Factor is', geom.GiveFactorForGeomSeq(12, 24))
print('------------------------------------------------')
print('Sum of n elements is', geom.GiveSumOfNElementsGeomSeq(2, 3, 4))
maxindex = 10

for i in range(1, maxindex + 1):

    element = geom.GiveGeomSeqElement(a1, factor, i)
    print('Term {:2d} = {:d}'.format(i, element))

#################################################
exNumber = 3
print("-" * 5, exNumber, "-" * 30)
# Code:

argument1 = 12
argument2 = 24

tmpFactor = geom.GiveFactorForGeomSeq(argument1, argument2)

print('For terms: {:d} and {:d} \nthe FACTOR is: {:.0f}'.format(
    argument1, argument2, tmpFactor))

#################################################
exNumber = 4
print("-" * 5, exNumber, "-" * 30)
# Code:

print(
    'Sum of 4 elements in geometrical progression starts from 2 with factor 3 is:'
)
print(geom.GiveSumOfNElementsGeomSeq(2, 3, 4))

#################################################
Esempio n. 3
0
import geom
print("Value of 2^64 is:", geom.GiveGeomSeqElement(1, 2, 64))
a1 = 3
factor = 2
maxindex = 10

for i in range(1, maxindex + 1):
    an = geom.GiveGeomSeqElement(a1=a1, factor=factor, index=i)
    print("element", i, "value:", an)

print("Factor is:", geom.GiveFactorForGeomSeq(12, 24))

print("Sum of n elements:", geom.GiveSumOfNElementsGeomSeq(2, 3, 4))
Esempio n. 4
0
import geom

# ZADANIE 1

print(geom.GiveGeomSeqElement(1, 2, 64))

# ZADANIE 2
a1 = 3
factor = 2
maxindex = 10

for i in range(1, maxindex):
    an = geom.GiveGeomSeqElement(a1=a1, factor=factor, index=i)
    print(i, an)

# ZADANIE 3

print(geom.GiveFactorForGeomSeq(12, 24))

# ZADANIE 4

print(geom.GiveSumOfNElementsGeomSeq(2, 3, 4))