From 3825606a0063c2334eddf0b6f1e9591e6ec6da96 Mon Sep 17 00:00:00 2001 From: Stanislav Mykhailenko Date: Tue, 24 Jan 2023 02:41:17 +0200 Subject: [PATCH] Update Lesson 2 Task 3 to be even more simple --- Lesson_2/task3.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/Lesson_2/task3.py b/Lesson_2/task3.py index 202bb19..f4629f6 100644 --- a/Lesson_2/task3.py +++ b/Lesson_2/task3.py @@ -2,24 +2,17 @@ # Author: Stanislav Mykhailenko # License: Unlicense -# Return codes: -# 0 - OK -# 1 - Invalid number entered +try: + number = int(input("Enter a natural number: ")) + if number < 1: + raise ValueError("A natural number is required.") -import math, sys + for i in range(number, 0, -1): + currentNumber = i + for j in range(currentNumber, 0, -1): + print(j, end='') + if j > 1: print(' ', end='') + print('') -def numberError(): +except ValueError: print("Invalid number entered.") - sys.exit(1) - -try: number = int(input("Enter a natural number: ")) -except ValueError: numberError() - -if number < 1: numberError() - -for i in range(number, 0, -1): - currentNumber = i - for j in range(currentNumber, 0, -1): - print(j, end='') - if j > 1: print(' ', end='') - print('')