Примеры кода (1161128), страница 2
Текст из файла (страница 2)
(Факториал)factorial = lambda n : 1 if n == 0 else n * factorial(n - 1)def factorial_simple(n):if n == 0:return 1else:return factorial_simple(n - 1) * na = int(input()) #input считывает строкуprint(factorial(a))) #вызов функцииПример функции-генератора (итераторы)def squares():n = 1while(True):yield n * nn += 1for x in squares():print(x)# output: 1 4 9 16 25 ...Ada95Пример с инкапсуляцией и наследованиемpackage File_System istype File is tagged private;procedure View(F : File);type Ada_File is new File with private;procedure View(F : Ada_File);privatetype File is taggedrecordName : String(1..20);end record;type Ada_File is new File withrecordCompiled : Boolean := False;end record;end File_System;Классический GCD. Использование функций, циклов и вывода.with Ada.Text_Io; use Ada.Text_Io;procedure Gcd_Test isfunction Gcd (A, B : Integer) return Integer isM : Integer := A;N : Integer := B;T : Integer;beginwhile N /= 0 loopT := M;M := N;N := T mod N;end loop;return M;end Gcd;beginPut_Line("GCD of 100, 5 is" & Integer'Image(Gcd(100, 5)));Put_Line("GCD of 5, 100 is" & Integer'Image(Gcd(5, 100)));Put_Line("GCD of 7, 23 is" & Integer'Image(Gcd(7, 23)));end Gcd_Test;.