侧边栏壁纸
博主头像
小萌小筑博主等级

叹一句当时只道是寻常

  • 累计撰写 12 篇文章
  • 累计创建 6 个标签
  • 累计收到 1 条评论

目 录CONTENT

文章目录

C大调自然音阶品格记忆

超级小萌哥
2026-01-28 / 0 评论 / 0 点赞 / 3 阅读 / 3864 字

数学,什么都是数学🤓

数学,竟有如此魅力🧐

这段代码用来记忆指板上的音阶,没有想象中那么难,或许万事都没有想象中那么难🤨

另附在线运行python代码的网站

ProgramizOnlineGDB

import random
from typing import Optional

ALL_NOTES = [
    ['E', 'F', '#F', 'G', '#G', 'A', '#A', 'B', 'C', '#C', 'D', '#D', 'E'],
    ['B', 'C', '#C', 'D', '#D', 'E', 'F', '#F', 'G', '#G', 'A', '#A', 'B'],
    ['G', '#G', 'A', '#A', 'B', 'C', '#C', 'D', '#D', 'E', 'F', '#F', 'G'],
    ['D', '#D', 'E', 'F', '#F', 'G', '#G', 'A', '#A', 'B', 'C', '#C', 'D'],
    ['A', '#A', 'B', 'C', '#C', 'D', '#D', 'E', 'F', '#F', 'G', '#G', 'A'],
    ['E', 'F', '#F', 'G', '#G', 'A', '#A', 'B', 'C', '#C', 'D', '#D', 'E']
]


def ask_line_of_note(line, std: bool = True):
    r = random.Random()
    while True:
        if not line:
            r_line = r.randrange(0, len(ALL_NOTES)) + 1
        else:
            r_line = line[r.randrange(0, len(line))]
        notes = ALL_NOTES[r_line - 1]

        new_note_index = random.randrange(0, len(notes))
        new_note = notes[new_note_index]
        if std and '#' in new_note:
            continue
        print(f'========{r_line} Line=========')
        print(new_note)
        temp = int(input())
        if temp == new_note_index or (new_note_index in [0, 12] and temp in [0, 12]):
            print('√')
        else:
            print(new_note_index)


def aks_note_of_line(line, std: bool = True):
    r = random.Random()
    while True:
        if not line:
            r_line = r.randrange(0, len(ALL_NOTES)) + 1
        else:
            r_line = line[r.randrange(0, len(line))]
        notes = ALL_NOTES[r_line - 1]

        new_note_index = random.randrange(0, len(notes))
        new_note = notes[new_note_index]
        if std and '#' in new_note:
            continue
        print(f'========{r_line} Line=========')
        print(f'{r_line} Line {new_note_index} Pin')
        temp = input().upper()
        if temp == new_note:
            print('√')
        else:
            print(new_note)


def ask_lines_of_note(std: bool = True):
    while True:
        note = ALL_NOTES[0][random.randrange(0, len(ALL_NOTES[0]))]
        if std and '#' in note:
            continue
        print(f"=======Note {note}======")
        line_idx = [i for i in range(len(ALL_NOTES))]
        random.shuffle(line_idx)
        for line in line_idx:
            print(f'Line {line + 1}', end='——')
            idx = int(input())
            ans = ALL_NOTES[line].index(note)
            if idx == ans:
                print('√')
            else:
                print(ans)
        print('_' * 27)
        for line in range(0, len(ALL_NOTES)):
            note_idx = ALL_NOTES[line].index(note)
            print('|' + ' |' * note_idx + f'{note}|' + ' |' * (12 - note_idx))
            print('_' * 27)


if __name__ == '__main__':
    ask_lines_of_note()
    # aks_note_of_line([1, 2, 3])
    # ask_line_of_note([1, 2, 3])

0

评论区