22 - python & all web labs
This commit is contained in:
29
labPython/lab21/task_1.py
Normal file
29
labPython/lab21/task_1.py
Normal file
@@ -0,0 +1,29 @@
|
||||
import math
|
||||
|
||||
|
||||
def simple_gen5(lst):
|
||||
for x in lst:
|
||||
if x >= 0:
|
||||
yield math.sqrt(x)
|
||||
else:
|
||||
yield None
|
||||
|
||||
|
||||
while True:
|
||||
print("генерация квадратных корней")
|
||||
print("1 - Ввести список")
|
||||
print("0 - Выход")
|
||||
choice = input("Выбор: ")
|
||||
|
||||
if choice == "0":
|
||||
break
|
||||
|
||||
if choice == "1":
|
||||
try:
|
||||
data = list(map(int, input("Введите числа через пробел: ").split()))
|
||||
gen = simple_gen5(data)
|
||||
print("Результат:")
|
||||
for val in gen:
|
||||
print(val)
|
||||
except:
|
||||
print("Ошибка ввода")
|
||||
Reference in New Issue
Block a user