From e1f14305a722d2e0ff1eb3f68f0e5e17f6c7b7c2 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Thu, 27 Oct 2022 19:05:50 +0300 Subject: [PATCH] Add Lesson 2 Task 3 --- Lesson_2/task3.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 Lesson_2/task3.py diff --git a/Lesson_2/task3.py b/Lesson_2/task3.py new file mode 100644 index 0000000..3183904 --- /dev/null +++ b/Lesson_2/task3.py @@ -0,0 +1,27 @@ +# Lesson 2 Task 3: display all numbers from n to 1, then remove the first number and repeat while n > 0 +# Author: Stanislav Mykhailenko +# License: Unlicense + +# Return codes: +# 0 - OK +# 1 - Invalid number entered + +import math, sys + +def numberError(): + print("Invalid number entered.") + sys.exit(1) + +try: number = int(input("Enter a natural number: ")) +except ValueError: numberError() + +if number < 1: numberError() + +while number > 0: + currentNumber = number + while currentNumber > 0: + print(currentNumber, end='') + if currentNumber > 1: print(' ', end='') + currentNumber = currentNumber - 1 + print('') + number = number - 1