Update Lesson 2 Task 3 to make it more simple

This commit is contained in:
Stanislav Mykhailenko 2023-01-07 20:23:42 +02:00
parent 377b713b83
commit ba3cdad458
GPG key ID: 1E95E66A9C9D6A36

View file

@ -2,22 +2,15 @@
# 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:
if not error:
while number > 0:
currentNumber = number
while currentNumber > 0:
print(currentNumber, end='')
@ -25,3 +18,5 @@ while number > 0:
currentNumber = currentNumber - 1
print('')
number = number - 1
else:
print("Invalid number entered.")