diff --git a/Lesson2/Task1.py b/Lesson2/Task1.py new file mode 100644 index 0000000..3b97ba0 --- /dev/null +++ b/Lesson2/Task1.py @@ -0,0 +1,19 @@ +while True: + operator = input('Выберите операцию (+,-,/,*,) или введите 0 для завершения работы: ') + if operator not in ['0', '+', '-', '/', '*']: + print('Операция не распознана') + if operator == '0': + break + numa = float(input('Введите число a: ')) + numb = float(input('Введите число b: ')) + if operator == '+': + print(f'Сумма равна {numa+numb}') + if operator == '-': + print(f'Разность равна {numa-numb}') + if operator == '*': + print(f'Результат умножения: {numa*numb}') + if operator == '/': + if 0 != numb: + print(f'Результат деления: {numa/numb}') + else: + print('Не дели на 0!') diff --git a/Lesson2/Task3.py b/Lesson2/Task3.py new file mode 100644 index 0000000..ba4c394 --- /dev/null +++ b/Lesson2/Task3.py @@ -0,0 +1,5 @@ +number = input('Введите целое число: ') +nlen = len(number) - 1 +while nlen >= 0: + print(number[nlen], end='') + nlen = nlen - 1 diff --git a/Lesson2/Task8.py b/Lesson2/Task8.py new file mode 100644 index 0000000..2e24750 --- /dev/null +++ b/Lesson2/Task8.py @@ -0,0 +1,8 @@ +number = input('Введите целое число: ') +count = input('Введите цифру которую необходимо посчитать: ') +counter = 0 +for i, c in enumerate(number): + print(c) + if c == count: + counter = counter + 1 +print(f'Число заданных цифр в числе: {counter}') diff --git a/Lesson2/task2.py b/Lesson2/task2.py index e69de29..73c220f 100644 --- a/Lesson2/task2.py +++ b/Lesson2/task2.py @@ -0,0 +1,12 @@ +number = input('Введите целое число: ') +oddcnt = nonoddcnt = 0 +for i, c in enumerate(number): + check = int(c) + if check % 2 == 0: + oddcnt = oddcnt + 1 + else: + nonoddcnt = nonoddcnt + 1 +print(f'Число четных цифр: {oddcnt}') +print(f'Число нечетных цифр: {nonoddcnt}') + + diff --git a/Lesson2/task5.py b/Lesson2/task5.py index e69de29..5256258 100644 --- a/Lesson2/task5.py +++ b/Lesson2/task5.py @@ -0,0 +1,13 @@ +start = 32 +end = 128 +symbolsinline = 10 +i = start +while True: + c = symbolsinline + while c > 0: + print(f'{i} - {chr(i)}', end=' ') + i = i + 1 + c = c - 1 + if i > end: + exit(0) + print() diff --git a/Lesson2/task6.py b/Lesson2/task6.py new file mode 100644 index 0000000..f8776b9 --- /dev/null +++ b/Lesson2/task6.py @@ -0,0 +1,17 @@ +import random + +number = random.randint(0, 100) +i = 10 +print('Загадано число от 0 до 100. У вас есть 10 попыток чтобы отгадать число') +while i > 0: + answer = int(input('Введите вариант ответа: ')) + if answer == number: + print('Вы угадали!') + exit(0) + if answer > number: + print('Ваше число больше загаданного') + if answer < number: + print('Ваше число меньше загаданного') + i = i - 1 + print(f'Попыток осталось: {i}') +print(f'Вы не угадали! Было загадано число {number}')