jackfrued / jackfrued/Python-100-Days

Day08 - 面向对象编程基础 定义一个类描述数字时钟

Open
#169 1 comment 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Jupyter Notebook
Stars
187k
Forks
55.8k
PR merge metrics
No merged PRs in 30d

Description

定义一个类描述数字时钟
未import time模块导致出错
from time import sleep
class Clock(object):
"""数字时钟"""

def __init__(self, hour=0, minute=0, second=0):
    """初始化方法

    :param hour: 时
    :param minute: 分
    :param second: 秒
    """
    self._hour = hour
    self._minute = minute
    self._second = second

def run(self):
    """走字"""
    self._second += 1
    if self._second == 60:
        self._second = 0
        self._minute += 1
        if self._minute == 60:
            self._minute = 0
            self._hour += 1
            if self._hour == 24:
                self._hour = 0

def show(self):
    """显示时间"""
    return '%02d:%02d:%02d' % \
           (self._hour, self._minute, self._second)

def main():
clock = Clock(23, 59, 58)
while True:
print(clock.show())
sleep(1)
clock.run()

if name == 'main':
main()

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the clock example in the issue body and its main() entry point; verify the time import used by sleep is available when the script runs. Done means the example starts without an import error and the clock continues to display advancing time.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.