diff --git a/hometask1/task1.py b/hometask1/task1.py new file mode 100644 index 0000000..b7ace86 --- /dev/null +++ b/hometask1/task1.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python +# nevl 2021 + +if __name__ == '__main__': + # variables + test_int = 1 + test_float = 1.1 + test_str = 'String' + test_bool = True + test_list = [1, 2] + test_tuple = (3, 4) + test_dict = { + "first": 1, + "second": 2 + } + + # print section + print(test_int) + print(test_float) + print(test_str) + print(test_bool) + print(test_list) + print(test_tuple) + print(test_dict) + + # input section + tmp_str = input('Write string: ') + print(tmp_str, type(tmp_str)) + tmp_int = input('Write integer: ') + print(tmp_int, type(tmp_int)) + tmp_float = input('Write float: ') + print(tmp_float, type(tmp_float)) + + print('Done') diff --git a/hometask1/task2.py b/hometask1/task2.py new file mode 100644 index 0000000..c117687 --- /dev/null +++ b/hometask1/task2.py @@ -0,0 +1,18 @@ +#!/usr/bin/env python +# nevl 2021 + +if __name__ == '__main__': + # fetch count of seconds and check for number + while True: + tmp = input('Input seconds: ') + try: + tmp = int(tmp) + break + except: + print('Input not a number') + + # calculate time + hours = tmp // 3600 + minutes = (tmp - (hours * 3600)) // 60 + seconds = tmp % 60 + print(f'{hours:02}:{minutes:02}:{seconds:02}') diff --git a/hometask1/task3.py b/hometask1/task3.py new file mode 100644 index 0000000..f48ae97 --- /dev/null +++ b/hometask1/task3.py @@ -0,0 +1,24 @@ +#!/usr/bin/env python +# nevl 2021 + +if __name__ == '__main__': + # fetch number and check + while True: + tmp = input('Input number: ') + try: + tmp = int(tmp) + if tmp < 0 or tmp > 9: + print('Enter only one symbol.') + continue + else: + break + except: + print('Not a number. Try again.') + continue + + # make new numbers in strings + s2 = f'{tmp}'*2 + s3 = f'{tmp}'*3 + + # calculate + print(tmp + int(s2) + int(s3)) diff --git a/hometask1/task4.py b/hometask1/task4.py new file mode 100644 index 0000000..b95d499 --- /dev/null +++ b/hometask1/task4.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python +# nevl 2021 + +if __name__ == '__main__': + # fetch number and check + while True: + tmp = input('Input number: ') + try: + tmp = int(tmp) + if tmp <= 0: + print('Input positive number.') + continue + break + except: + print('Input not a number') + + # find the biggest number + number = 0 + while tmp > 0: + t = tmp % 10 + if t > number: + number = t + tmp //= 10 + + print(f'The biggest number is: {number}') diff --git a/hometask1/task5.py b/hometask1/task5.py new file mode 100644 index 0000000..180ef6e --- /dev/null +++ b/hometask1/task5.py @@ -0,0 +1,45 @@ +#!/usr/bin/env python +# nevl 2021 + +def is_number(str): + try: + tmp = float(str) + if tmp <= 0: + print('Input positive number.') + return True + except: + print('Input not a number') + return False + +if __name__ == '__main__': + # fetch proceeds + while True: + proceeds = input('Input proceeds: ') + if is_number(proceeds): + break + + # fetch costs + while True: + costs = input('Input costs: ') + if is_number(costs): + break + + # check financial results + profit = float(proceeds) - float(costs) + financial_results = 'profit' if profit > 0 else 'loss' + print(f'Financial results are {financial_results}') + + # profitability of proceeds + if profit > 0: + profitability_of_proceeds = profit / float(proceeds) + print(f'Profitability of proceeds = {profitability_of_proceeds}') + + # number of employees + while True: + number_of_employees = input('Input number of employees: ') + if is_number(number_of_employees): + break + + # profit per employee + profit_per_employee = profit / float(number_of_employees) + print(f'Profit {profit_per_employee} per employee.') diff --git a/hometask1/task6.py b/hometask1/task6.py new file mode 100644 index 0000000..6d6d542 --- /dev/null +++ b/hometask1/task6.py @@ -0,0 +1,33 @@ +#!/usr/bin/env python +# nevl 2021 + +def is_int(str): + try: + tmp = int(str) + if tmp <= 0: + print('Input positive number.') + return True + except: + print('Input not a number') + return False + +if __name__ == '__main__': + # fetch proceeds + while True: + a = input('Input a: ') + if is_int(a): + break + + # fetch costs + while True: + b = input('Input b: ') + if is_int(b): + break + + count = 1 + distance = float(a) + while distance < int(b): + distance += distance * 0.1 + count += 1 + + print(count)