Update Lesson 2 Task 3 to make it more simple in another way
This commit is contained in:
parent
c77d218010
commit
838f6cd131
1 changed files with 17 additions and 14 deletions
|
@ -2,21 +2,24 @@
|
||||||
# Author: Stanislav Mykhailenko
|
# Author: Stanislav Mykhailenko
|
||||||
# License: Unlicense
|
# License: Unlicense
|
||||||
|
|
||||||
error = False
|
# 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: "))
|
try: number = int(input("Enter a natural number: "))
|
||||||
except ValueError: error = True
|
except ValueError: numberError()
|
||||||
|
|
||||||
if not error and number < 1: error = True
|
if number < 1: numberError()
|
||||||
|
|
||||||
if not error:
|
for i in range(number, 0, -1):
|
||||||
while number > 0:
|
currentNumber = i
|
||||||
currentNumber = number
|
for j in range(currentNumber, 0, -1):
|
||||||
while currentNumber > 0:
|
print(j, end='')
|
||||||
print(currentNumber, end='')
|
if j > 1: print(' ', end='')
|
||||||
if currentNumber > 1: print(' ', end='')
|
|
||||||
currentNumber = currentNumber - 1
|
|
||||||
print('')
|
print('')
|
||||||
number = number - 1
|
|
||||||
else:
|
|
||||||
print("Invalid number entered.")
|
|
||||||
|
|
Reference in a new issue