Жұмыстың мақсаты.Шартты операторлар, циклдар, екi өлшемдi массивтерге есептер шығару және функцияларды, файлдарды қолдану.
1-есеп
def func():
f=open("output.txt",'w')
a=int(input("a="))
k=1
while k<=a:
i=1
while i<=k:
f.write(" 5 ")
i+=1
f.write("\n")
k+=1
func()
2 есеп
def func(a,b):
f=open("output.txt",'w')
i=a
b=5
while i>=1:
k=1
while k<=i:
f.write(str(b))
k+=1
b+=1
f.write("\n")
i-=1
func(5,5)
3-есеп
def func():
f=open("output.txt",'w')
N=int(input("n="))
for i in range(1,N+1):
for k in range(1,i+1):
f.write(str(i))
f.write("\n")
func()
4-есеп
def func(a,b):
f=open("output.txt",'w')
i=a
b=5
while i>=1:
k=1
while k<=i:
f.write(str(b))
k+=1
b+=1
f.write("\n")
i-=1
func(5,5
5-есеп
def func():
m, n = 7, 7
if m > n:
a = [[0] * m for i in range(m)]
else:
a = [[0] * n for i in range(n)]
for i in range(m):
for j in range(n):
if i == j:
a[i][j] = 1
for i in range(m):
for j in range(n):
a[i][n - i - 1] = 1
f = open("output.txt", 'w')
for i in range(7):
for j in range(7):
f.write(f"{a[i][j]}" + '\t')
f.write(f"\n")
func()
6-есеп
def func():
m, n = 7, 7
if m > n:
a = [[0] * m for i in range(m)]
else:
a = [[0] * n for i in range(n)]
for i in range(m):
for j in range(n):
if i == j:
a[i][j] = 1
for i in range(m):
a[i][3] = 1
for i in range(m):
a[3][i] = 1
for i in range(m):
for j in range(n):
a[i][n - i - 1] = 1
f = open("output.txt", 'w')
for i in range(7):
for j in range(7):
f.write(f"{a[i][j]}" + '\t')
f.write(f"\n")
func()