From 897dba4e6f7dce02c206ccd13660f44676f49675 Mon Sep 17 00:00:00 2001 From: M7mdQash Date: Thu, 19 Feb 2026 11:42:42 +0300 Subject: [PATCH 1/4] did both labs functions --- bonus-lab.py | 19 +++++++++++++++++++ funcLab.py | 25 +++++++++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 bonus-lab.py create mode 100644 funcLab.py diff --git a/bonus-lab.py b/bonus-lab.py new file mode 100644 index 0000000..a8395aa --- /dev/null +++ b/bonus-lab.py @@ -0,0 +1,19 @@ +def pyramidFunction(n): + + ''' + Docstring for pyramidFunction + this funtion takes a number n and prints a pyramid of numbers with n levels but as a string variable + :param n: the input which determines the size of the pyramid + ''' + var4print ="" + num =n + for i in range(1, n+1): + for j in range(1, num+1): + var4print += f' {num} ' + num -= 1 + + var4print += "\n" + num = n - i + print(var4print) + +pyramidFunction(5) \ No newline at end of file diff --git a/funcLab.py b/funcLab.py new file mode 100644 index 0000000..dec06c1 --- /dev/null +++ b/funcLab.py @@ -0,0 +1,25 @@ +def pyramidFunction(n): + + ''' + Docstring for pyramidFunction + this funtion takes a number n and prints a pyramid of numbers with n levels, that is flipped to the right. + :param n: the input which determines the size of the pyramid + ''' + num =n + for i in range(1, n+1): + for j in range(1, num+1): + print(f' {num} ',end="") + num -= 1 + + print("") + num = n - i +#end func + +if int(input("chose to use the function or get docs on it, 1 for using the function, 2 for getting docs:")) == 1: + pyramidFunction(int(input("enter the number of levels for the pyramid:"))) +elif 2: + print(pyramidFunction.__doc__) +else: + print("invalid input") +#help(pyramidFunction) +#' ' * (n - i) + '*' * (2 * i - 1) \ No newline at end of file From b05abc2bc1b019841dc6295fb7d85cba81e31922 Mon Sep 17 00:00:00 2001 From: M7mdQash Date: Thu, 19 Feb 2026 11:43:43 +0300 Subject: [PATCH 2/4] implemented flow control for bonus lab --- bonus-lab.py | 7 ++++++- funcLab.py | 2 -- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/bonus-lab.py b/bonus-lab.py index a8395aa..af2d163 100644 --- a/bonus-lab.py +++ b/bonus-lab.py @@ -16,4 +16,9 @@ def pyramidFunction(n): num = n - i print(var4print) -pyramidFunction(5) \ No newline at end of file +if int(input("chose to use the function or get docs on it, 1 for using the function, 2 for getting docs:")) == 1: + pyramidFunction(int(input("enter the number of levels for the pyramid:"))) +elif 2: + print(pyramidFunction.__doc__) +else: + print("invalid input") \ No newline at end of file diff --git a/funcLab.py b/funcLab.py index dec06c1..a613773 100644 --- a/funcLab.py +++ b/funcLab.py @@ -21,5 +21,3 @@ def pyramidFunction(n): print(pyramidFunction.__doc__) else: print("invalid input") -#help(pyramidFunction) -#' ' * (n - i) + '*' * (2 * i - 1) \ No newline at end of file From 25698c40d4fa4c17b3e2502584fca3bc9c0d44b8 Mon Sep 17 00:00:00 2001 From: M7mdQash Date: Thu, 19 Feb 2026 11:50:36 +0300 Subject: [PATCH 3/4] used return function --- bonus-lab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonus-lab.py b/bonus-lab.py index af2d163..bc7f0db 100644 --- a/bonus-lab.py +++ b/bonus-lab.py @@ -14,7 +14,7 @@ def pyramidFunction(n): var4print += "\n" num = n - i - print(var4print) + return var4print if int(input("chose to use the function or get docs on it, 1 for using the function, 2 for getting docs:")) == 1: pyramidFunction(int(input("enter the number of levels for the pyramid:"))) From 627f7f7ffaebf0b383aca8755b4bc177a1f2edca Mon Sep 17 00:00:00 2001 From: M7mdQash Date: Thu, 19 Feb 2026 11:51:50 +0300 Subject: [PATCH 4/4] fixed return function --- bonus-lab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bonus-lab.py b/bonus-lab.py index bc7f0db..eac36c6 100644 --- a/bonus-lab.py +++ b/bonus-lab.py @@ -17,7 +17,7 @@ def pyramidFunction(n): return var4print if int(input("chose to use the function or get docs on it, 1 for using the function, 2 for getting docs:")) == 1: - pyramidFunction(int(input("enter the number of levels for the pyramid:"))) + print(pyramidFunction(int(input("enter the number of levels for the pyramid:")))) elif 2: print(pyramidFunction.__doc__) else: