diff --git a/Hello.py b/Hello.py new file mode 100644 index 0000000..8eb74cf --- /dev/null +++ b/Hello.py @@ -0,0 +1 @@ +print('Hello world') \ No newline at end of file diff --git a/Lesson_1/.idea/.gitignore b/Lesson_1/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/Lesson_1/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/Lesson_1/.idea/Lesson_1.iml b/Lesson_1/.idea/Lesson_1.iml new file mode 100644 index 0000000..74d515a --- /dev/null +++ b/Lesson_1/.idea/Lesson_1.iml @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/Lesson_1/.idea/inspectionProfiles/profiles_settings.xml b/Lesson_1/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/Lesson_1/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/Lesson_1/.idea/misc.xml b/Lesson_1/.idea/misc.xml new file mode 100644 index 0000000..a4652f3 --- /dev/null +++ b/Lesson_1/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Lesson_1/.idea/modules.xml b/Lesson_1/.idea/modules.xml new file mode 100644 index 0000000..a04d3c7 --- /dev/null +++ b/Lesson_1/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Lesson_1/.idea/vcs.xml b/Lesson_1/.idea/vcs.xml new file mode 100644 index 0000000..6c0b863 --- /dev/null +++ b/Lesson_1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Lesson_1/info.py b/Lesson_1/info.py new file mode 100644 index 0000000..94e3a87 --- /dev/null +++ b/Lesson_1/info.py @@ -0,0 +1,16 @@ +# This is a sample Python script. + +# Press ⌃R to execute it or replace it with your code. +# Press Double ⇧ to search everywhere for classes, files, tool windows, actions, and settings. + + +def print_hi(name): + # Use a breakpoint in the code line below to debug your script. + print(f'Hi, {name}') # Press ⌘F8 to toggle the breakpoint. + + +# Press the green button in the gutter to run the script. +if __name__ == '__main__': + print_hi('PyCharm') + +# See PyCharm help at https://www.jetbrains.com/help/pycharm/ diff --git a/Lesson_1/task_1.py b/Lesson_1/task_1.py new file mode 100644 index 0000000..33c38c9 --- /dev/null +++ b/Lesson_1/task_1.py @@ -0,0 +1,19 @@ +# Поработайте с переменными, создайте несколько, выведите на экран. +# Запросите у пользователя некоторые числа и строки и сохраните в переменные, +# затем выведите на экран. +a = 10 +b = 45.23 +c = a + b +d = a - b +x = c / d +print(a) +print(b) +print(c) +print(d) +print(x) + +name = input('Please, enter your name: ') +print("Hi, %s!" % name) +i = int(input('Please, enter a random number: ')) +a = i + i * i +print('Thank you very much. The answer is: %d' %a) diff --git a/Lesson_1/task_2.py b/Lesson_1/task_2.py new file mode 100644 index 0000000..043e18f --- /dev/null +++ b/Lesson_1/task_2.py @@ -0,0 +1,8 @@ +# Пользователь вводит время в секундах. +# Переведите время в часы, минуты, секунды и выведите в формате чч:мм:сс. +# Используйте форматирование строк. +Interval = int(input('Please, enter the time interval in seconds: ')) +H = Interval // 3600 +M = (Interval - H * 3600) // 60 +S = Interval - (H * 3600 + M * 60) +input('If your time interval is equal to %d than the current time is: ' % (Interval) + '%02d:%02d:%02d' % (H, M, S)) diff --git a/Lesson_1/task_3.py b/Lesson_1/task_3.py new file mode 100644 index 0000000..e7a3517 --- /dev/null +++ b/Lesson_1/task_3.py @@ -0,0 +1,11 @@ +# Узнайте у пользователя число n. +# Найдите сумму чисел n + nn + nnn. +# Например, пользователь ввёл число 3. +# Считаем 3 + 33 + 333 = 369. + +n = int(input('Please, enter a random value = ')) +x = str(n) +nn = x + x +nnn = x + x + x +cal = n + int(nn) + int(nnn) +print('Based on your value: %d ' % n + 'the result of the calculation is = %d' % cal) diff --git a/Lesson_1/task_4.py b/Lesson_1/task_4.py new file mode 100644 index 0000000..1474b41 --- /dev/null +++ b/Lesson_1/task_4.py @@ -0,0 +1,14 @@ +# Пользователь вводит целое положительное число. +# Найдите самую большую цифру в числе. +# Для решения используйте цикл while и арифметические операции. +val = int(input('Please, enter positive value: ')) +max_val = val % 10 +num = val +while num > 0: + dgt = num % 10 + if dgt > max_val: + max_val = dgt + if max_val == 9: + break + num = num // 10 +print(f'The largest digit in {val} is = {max_val}') diff --git a/Lesson_1/task_5.py b/Lesson_1/task_5.py new file mode 100644 index 0000000..3ebe687 --- /dev/null +++ b/Lesson_1/task_5.py @@ -0,0 +1,18 @@ +# Запросите у пользователя значения выручки и издержек фирмы. +# Определите, с каким финансовым результатом работает фирма. +# Например, прибыль — выручка больше издержек, +# или убыток — издержки больше выручки. Выведите соответствующее сообщение. +# Если фирма отработала с прибылью, вычислите рентабельность выручки. Э +# то отношение прибыли к выручке. Далее запросите численность сотрудников +# фирмы и определите прибыль фирмы в расчёте на одного сотрудника. + +rev = float(input('Please enter revenue of the company: ')) +cos = float(input('Please enter costs of the company: ')) +inc = rev - cos +if inc > 0: + print('The company is profitable.') + print(f'Return on revenue is: {inc / rev: .2f}') + staff = int(input('Please enter the number of employees:')) + print(f'Profit per employee is: {rev / staff: .2f}') +else: + print('The company is unprofitable.') diff --git a/Lesson_1/task_6.py b/Lesson_1/task_6.py new file mode 100644 index 0000000..3c8bbac --- /dev/null +++ b/Lesson_1/task_6.py @@ -0,0 +1,15 @@ +# Спортсмен занимается ежедневными пробежками. +# В первый день его результат составил a километров. +# Каждый день спортсмен увеличивал результат +# на 10% относительно предыдущего. Требуется определить номер дня, +# на который результат спортсмена составит не менее b километров. +# Программа должна принимать значения параметров a и b и +# выводить одно натуральное число — номер дня. + +a = int(input('Please enter the current distance value ')) +b = int(input('Please enter the distance you would like to run ')) +ad = 1 # ad = amount of the days +while a < b: + a = 1.1 * a + ad += 1 +print(f'If you increase your distance by 10% you will be able to run2 {b} km in {ad} days') \ No newline at end of file diff --git a/Lesson_2/task_1.py b/Lesson_2/task_1.py new file mode 100644 index 0000000..688e473 --- /dev/null +++ b/Lesson_2/task_1.py @@ -0,0 +1,8 @@ +# Создать список и заполнить его элементами различных типов данных. +# Реализовать скрипт проверки типа данных каждого элемента. +# Использовать функцию type() для проверки типа. +# Элементы списка можно не запрашивать у пользователя, а указать явно, в программе. + +main_list = [56, 3.76, False, "Hello", ('2', 'a', '6'), ['b', '3', 'c'], {'123': 'key-1', '321': 'key-2'}] +for i in main_list: + print(f'{i} is {type(i)}') diff --git a/Lesson_2/task_2.py b/Lesson_2/task_2.py new file mode 100644 index 0000000..ed2c1ec --- /dev/null +++ b/Lesson_2/task_2.py @@ -0,0 +1,22 @@ +# Для списка реализовать обмен значений соседних элементов. +# Значениями обмениваются элементы с индексами 0 и 1, 2 и 3 и т. д. +# При нечётном количестве элементов последний сохранить на своём месте. +# Для заполнения списка элементов нужно использовать функцию input(). + +list_init = input('Please, enter the values separated by spaces: ').split() +print(list_init) +if len(list_init) % 2 == 0: + i = 0 + while i < len(list_init): + el = list_init[i] + list_init[i] = list_init[i + 1] + list_init[i + 1] = el + i += 2 +else: + i = 0 + while i < len(list_init) - 1: + el = list_init[i] + list_init[i] = list_init[i + 1] + list_init[i + 1] = el + i += 2 +print(list_init) diff --git a/Lesson_2/task_3.py b/Lesson_2/task_3.py new file mode 100644 index 0000000..4e08b38 --- /dev/null +++ b/Lesson_2/task_3.py @@ -0,0 +1,20 @@ +# Пользователь вводит месяц в виде целого числа от 1 до 12. +# Сообщить, к какому времени года относится месяц (зима, весна, лето, осень). +# Напишите решения через list и dict. + +m_dict = {'1': 'January', '2': 'February', '3': 'March', + '4': 'April', '5': 'May', '6': 'June', + '7': 'July', '8': 'August', '9': 'September', + '10': 'October', '11': 'November', '12': 'December'} +num_m = int(input('Please enter a month number from 1 to 12: ')) +a = num_m +if a == 1 or a == 2 or a == 12: + print("Your choiсe is the Winter season") +elif a == 3 or a == 4 or a == 5: + print("Your choiсe is the Spring season") +elif a == 6 or a == 7 or a == 8: + print("Your choiсe is the Summer season") +elif a == 9 or a == 10 or a == 11: + print("Your choiсe is the Autumn season") +else: + print("You made a mistake. Try again!")