Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Вивчайте Challenge: Creating the Sensor | Class Structures
Object Oriented Programming with Python
Секція 1. Розділ 9
single

single

Challenge: Creating the Sensor

Свайпніть щоб показати меню

Завдання

Проведіть, щоб почати кодувати

You are going to create a Sensor class to help keep track of numbers recorded by sensors. A sensor is a device that measures something, like temperature or light, and stores those measurements as a list of numbers called readings. Follow these steps to build your class:

  • Add a method called add_reading:
    • This method should take one value (a number).
    • Add this value to the sensor's list of readings.
  • Fill a method called average_reading:
    • This method should return the average (mean) of all the numbers in the readings list.
    • If there are no readings, it should return None instead of causing an error.
  • Add a method called reset_readings:
    • This method should remove all readings from the Sensor.
    • The readings list should become empty.

Рішення

Switch to desktopПерейдіть на комп'ютер для реальної практикиПродовжуйте з того місця, де ви зупинились, використовуючи один з наведених нижче варіантів
Все було зрозуміло?

Як ми можемо покращити це?

Дякуємо за ваш відгук!

Секція 1. Розділ 9
single

single

Запитати АІ

expand

Запитати АІ

ChatGPT

Запитайте про що завгодно або спробуйте одне із запропонованих запитань, щоб почати наш чат

some-alt