Update Lesson 2 Task 3 to make it more simple
This commit is contained in:
parent
377b713b83
commit
ba3cdad458
1 changed files with 14 additions and 19 deletions
|
@ -2,26 +2,21 @@
|
||||||
# Author: Stanislav Mykhailenko
|
# Author: Stanislav Mykhailenko
|
||||||
# License: Unlicense
|
# License: Unlicense
|
||||||
|
|
||||||
# Return codes:
|
error = False
|
||||||
# 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: "))
|
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:
|
||||||
currentNumber = number
|
while number > 0:
|
||||||
while currentNumber > 0:
|
currentNumber = number
|
||||||
print(currentNumber, end='')
|
while currentNumber > 0:
|
||||||
if currentNumber > 1: print(' ', end='')
|
print(currentNumber, end='')
|
||||||
currentNumber = currentNumber - 1
|
if currentNumber > 1: print(' ', end='')
|
||||||
print('')
|
currentNumber = currentNumber - 1
|
||||||
number = number - 1
|
print('')
|
||||||
|
number = number - 1
|
||||||
|
else:
|
||||||
|
print("Invalid number entered.")
|
||||||
|
|
Reference in a new issue