2005Человек2005
19.12.2020 11:56

Дан массив M. Запишите код программы массива, состоящий из 6 элементов (2х3). Выведите элементы массива.

Нажмите на рекламу ниже и сразу увидите ответ
Популярные вопросы:
Ответ:
niknikiforov91
09.12.2022 15:29

Решение задания с кодом из условия:

class Task():

   # все эти аттрибуты должны быть не у самого класса Задачи, а у объектов

   description = ''

   importance = 1

   # дату нужно выражать по-другому. datetime и Arrow в

   completion_month = ''

   completion_date = 1

def creation():  # как раз для этого существует __init__

   objective = Task()

   objective.description = input("Введите описание задачи: ")

   objective.importance = int(input("Введите важность задачи (от 1 до 5): "))

   objective.completion_month = input("Введите месяц сдачи: ")

   objective.completion_date = int(input("Введите дату сдачи: "))

   return objective

tasks = [creation(), creation(), creation()]

i = max(tasks, key=lambda task: task.importance)  # находит задачу с максимальной важностью (key=функция, возвращающая важность)

print("Самая важная задача: " + i.description + ", важность- " + str(i.importance) + ", месяц сдачи- " + i.completion_month + ", дата сдачи- " + str(i.completion_date))

i = min(tasks, key=lambda task: task.completion_date)  # находит задачу с максимальной датой сдачи (key=функция, возвращающая дату сдачи)

print("Самая задача: " + i.description + ", важность- " + str(i.importance) + ", месяц сдачи- " + i.completion_month + ", дата сдачи- " + str(i.completion_date))

Более правильное решение:

import datetime

class Task(object):

   def __init__(self, description, priority, due_date):

       self.description = str(description)

       priority = int(priority)

       if priority not in range(1, 6):

           raise ValueError("priority must be 1, 2, 3, 4, or 5")

       self.priority = priority

       if isinstance(due_date, datetime.datetime):

           due_date = due_date.date()

       if not isinstance(due_date, datetime.date):

           raise ValueError("due_date must be datetime.datetime "

                            "or datetime.date")

       self.due_date = due_date

   def __repr__(self):

       return f"Task({self.description}, {self.priority}, {self.due_date})"

   @classmethod

   def from_user_input(cls):

       description = input("Enter description of the task: ")

       while True:

           priority = input("Enter priority of the task (1-5): ")

           if priority in map(str, range(1, 6)):

               priority = int(priority)

               break

       

       date_format = "%d.%m.%Y"

       while True:

           due_date = input(f"Enter due date (like {date_format}): ")

           try:

               due_date = datetime.datetime.strptime(due_date, date_format).date()

           except ValueError:

               pass

           else:

               break

       return cls(description, priority, due_date)

   

tasks = [Task.from_user_input(),

        Task.from_user_input(),

        Task.from_user_input()]

print("The most important task:", max(tasks, key=lambda task: task.priority))

print("The most urgent task:", min(tasks, key=lambda task: task.due_date))

0,0(0 оценок)
Ответ:
Dinkaakissa20
12.05.2023 07:44

а)

var x, y :integer;

begin

 write ('x = ');

 readln(x);

 if (x<=0)

   then y:=x

   else if (x>=5)

          then y:=4

          else y:=sqr(x)*x;

 write ('y = ',y);

end.

б)

var x, y, xtreugA, ytreugA, xtreugB, ytreugB, xzentrokr, yzentrokr, radokr :integer;

begin

 write ('x = ');

 readln(x);

 write ('y = ');

 readln(y);

 xtreugA:= -4;

 ytreugA:= 0;

 xtreugB:= 0;

 ytreugB:= -5;

 

 xzentrokr:= 10;

 yzentrokr:= 7;

 radokr:=3;

 if x-xtreugA)*(ytreugB-ytreugA)-(y-ytreugA)*(xtreugB-xtreugA))<=0) and (x<=0) and (y<=0))

   then writeln('Popadanie v treugolnik')

   else writeln('Ne popadanie v treugolnik');

 if (sqrt(sqr(xzentrokr-x)+sqr(yzentrokr-y)) <= radokr)

   then writeln('Popadanie v okruznost')

   else writeln('Ne popadanie v okruznost');

end.

0,0(0 оценок)
Полный доступ
Позволит учиться лучше и быстрее. Неограниченный доступ к базе и ответам от экспертов и ai-bota Оформи подписку
logo
Начни делиться знаниями
Вход Регистрация
Что ты хочешь узнать?
Спроси ai-бота