22 - python & all web labs
This commit is contained in:
26
labPython/lab21/task_3.py
Normal file
26
labPython/lab21/task_3.py
Normal file
@@ -0,0 +1,26 @@
|
||||
def calc_gen4(a, r):
|
||||
current = a
|
||||
while True:
|
||||
yield current
|
||||
current *= r
|
||||
|
||||
|
||||
while True:
|
||||
print("геометрическая прогрессия")
|
||||
print("1 - Запустить")
|
||||
print("0 - Выход")
|
||||
choice = input("Выбор: ")
|
||||
|
||||
if choice == "0":
|
||||
break
|
||||
|
||||
if choice == "1":
|
||||
try:
|
||||
a = float(input("Первый член: "))
|
||||
r = float(input("Знаменатель: "))
|
||||
n = int(input("Сколько элементов вывести: "))
|
||||
gen = calc_gen4(a, r)
|
||||
for _ in range(n):
|
||||
print(next(gen))
|
||||
except:
|
||||
print("Ошибка ввода")
|
||||
Reference in New Issue
Block a user