-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson1_task_3.py
More file actions
42 lines (32 loc) · 1.42 KB
/
lesson1_task_3.py
File metadata and controls
42 lines (32 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'''3. Узнайте у пользователя число n. Найдите сумму чисел n + nn + nnn.'''
def input_integer():
# Проверяет ввод, возвращает введенное число
# Дает возможность повторить ввод при ошибке
while True:
_input = input('\nEnter a number:\n')
if _input.isdigit():
_input = int(_input)
return _input
else:
print('Error! signature you have typed is not a number!')
count = 0
tmp = user_input = input_integer()
while tmp: # Пока tmp True, не равняется 0
# tmp = tmp // 10
# Как только при отделении остатка от числа tmp доходит до 0 оно выдаёт False и цикл прекращается (🤯)
tmp //= 10
count += 1
nn_div = 10 ** count + 1
nnn_div = (10 ** (count * 2)) + nn_div
result = user_input + (user_input * nn_div) + (user_input * nnn_div)
print(f"\nCумма чисел n + nn + nnn = {result}\n")
""" Вариант со строкой """
print('-' * 31 + "\n")
while True:
user_num = input('Введите целое число:\n')
if user_num.isdigit():
break
else:
print('Error! Прошу!\n!!Введите положительное число!!\n')
result = int(user_num) + int(user_num * 2) + int(user_num * 3)
print(result)