From ba3cdad45866e417887d3ded87a3b6c8ce430dde Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Sat, 7 Jan 2023 20:23:42 +0200 Subject: [PATCH] Update Lesson 2 Task 3 to make it more simple --- Lesson_2/task3.py | 33 ++++++++++++++------------------- 1 file changed, 14 insertions(+), 19 deletions(-) diff --git a/Lesson_2/task3.py b/Lesson_2/task3.py index 3183904..75ef492 100644 --- a/Lesson_2/task3.py +++ b/Lesson_2/task3.py @@ -2,26 +2,21 @@ # 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) +error = False try: number = int(input("Enter a natural number: ")) -except ValueError: numberError() +except ValueError: error = True -if number < 1: numberError() +if not error and number < 1: error = True -while number > 0: - currentNumber = number - while currentNumber > 0: - print(currentNumber, end='') - if currentNumber > 1: print(' ', end='') - currentNumber = currentNumber - 1 - print('') - number = number - 1 +if not error: + while number > 0: + currentNumber = number + while currentNumber > 0: + print(currentNumber, end='') + if currentNumber > 1: print(' ', end='') + currentNumber = currentNumber - 1 + print('') + number = number - 1 +else: + print("Invalid number entered.")