简体   繁体   English

如何打印将某物从列表中取出并存储到其他位置

[英]How to print take something out of a list and store it elsewhere

I am making a music key theory test. 我正在进行音乐键理论测试。

In order to achieve something else that I won't explain right now here (maybe I will later though if this doesn't work), I need to take the root chord out of the list, store it somewhere else, and call back upon it for the user input when they are asked what key the chords come from. 为了实现我现在不会在这里解释的其他功能(如果稍后无法解决,也许我会稍后再说),我需要将根和弦从列表中删除,并将其存储在其他位置,然后调用当询问他们和弦来自什么琴键时,它供用户输入。

I don't know how to do this, but I am pretty sure it is possible. 我不知道该怎么做,但是我很确定这是可能的。 I would love it if someone could help me. 如果有人可以帮助我,我会喜欢的。 After I have this problem sorted out I will be much further. 解决了这个问题后,我会走得更远。

Before, I was trying to find someway to have the actual variable represent the variable, while representing what the variable contains. 以前,我试图找到某种方式让实际变量代表变量,同时代表变量包含的内容。 So then after printing the randomized chords from the variable, the user can input the key from which the chords come from, which I have as the variable. 因此,在从变量打印随机和弦之后,用户可以输入和弦来自的琴键,我将其作为变量。 But I don't think that will work. 但我认为这行不通。

import random

print('Key Theory Werkout')

Dmajor = {'D','E-','F⌗-','G','A','B-','C⌗dim'}
Gmajor = {'G','A-','B-','C','D','E-','F⌗dim'}
Cmajor = {'C','D-','E-','F','G','A-','Bdim'}
Fmajor = {'F','G-','A-','Bb','C','D-','Edim'}
Bbmajor = {'Bb','C-','D-','Eb','F','G-','Adim'}
Ebmajor = {'Eb','F-','G-','Ab','Bb','C-','Ddim'}
Abmajor = {'Ab','Bb-','C-','Db','Eb','F-','Gdim'}
Dbmajor = {'Db','Eb-','F-','Gb','Ab','Bb-','Cdim'}
Cxmajor = {'C⌗','D⌗-','E⌗-','F⌗','G⌗','A⌗-','B⌗dim'}
Gbmajor = {'Gb','Ab-','Bb-','Cb','Db','Eb-','Fdim'}
Fxmajor = {'F⌗','G⌗-','A⌗-','B','C⌗','D⌗-','E⌗dim'}
Bmajor = {'B','C⌗-','D⌗','E','F⌗','G⌗','A⌗dim'}
Cbmajor = {'Cb','Db-','Eb-','Fb','Gb','Ab-','B-dim'}
Emajor = {'E','F⌗-','G⌗-','A','B','C⌗-','D⌗dim'}
Amajor = {'A','B-','C⌗-','D','E','F⌗-','G⌗dim'}

questions = [Dmajor, Gmajor, Cmajor, Fmajor, Bbmajor, Ebmajor, 
Abmajor, Dbmajor, Cxmajor, Gbmajor, Fxmajor, Bmajor, Cbmajor, 
Emajor, Amajor]

print('Difficulty:Easy, Hard')

begin = input("Choose Difficulty:")
if begin == 'easy':
    while begin == "easy":
        q = random.choice(questions)
        qq = random.sample(list(q), 7)
        print(qq)
        answer = input('Please Provide the key:')
        if answer == q
'''HERE IS THE PROBLEM. Lets say the code outputs F, A-, Bb, C, D- 
for Dmajor. How can I have the user type in Dmajor and have it 
print correct, or incorrect? I am thinking I will have to put . 
entire blocks for each question, and then have the easy choose 
random out of all of those questions and that will be how I have to     
do it. But maybe there is an easier way.
'''
            print("correct")

I would like it to tell the user if they are correct or wrong, while keeping the randomness of questions, and chords it spits out exactly the way it is. 我想告诉用户它们是对还是错,同时保持问题的随机性,而和弦则完全按照问题的方式吐出。 What do I need to do? 我需要做什么?

Maybe you can try using a dictionary to represent your questions, like this: 也许您可以尝试使用字典来表示您的问题,例如:

questions = {
  'Dmajor': {'D','E-','F⌗-','G','A','B-','C⌗dim'},
  'Gmajor': {'G','A-','B-','C','D','E-','F⌗dim'},
  'Cmajor': {'C','D-','E-','F','G','A-','Bdim'},
  'Fmajor': {'F','G-','A-','Bb','C','D-','Edim'},
  'Bbmajor': {'Bb','C-','D-','Eb','F','G-','Adim'},
  'Ebmajor': {'Eb','F-','G-','Ab','Bb','C-','Ddim'},
  'Abmajor': {'Ab','Bb-','C-','Db','Eb','F-','Gdim'},
  'Dbmajor': {'Db','Eb-','F-','Gb','Ab','Bb-','Cdim'},
  'Cxmajor': {'C⌗','D⌗-','E⌗-','F⌗','G⌗','A⌗-','B⌗dim'},
  'Gbmajor': {'Gb','Ab-','Bb-','Cb','Db','Eb-','Fdim'},
  'Fxmajor': {'F⌗','G⌗-','A⌗-','B','C⌗','D⌗-','E⌗dim'},
  'Bmajor': {'B','C⌗-','D⌗','E','F⌗','G⌗','A⌗dim'},
  'Cbmajor': {'Cb','Db-','Eb-','Fb','Gb','Ab-','B-dim'},
  'Emajor': {'E','F⌗-','G⌗-','A','B','C⌗-','D⌗dim'},
  'Amajor': {'A','B-','C⌗-','D','E','F⌗-','G⌗dim'},
}

Then, you select a random question like this: 然后,您选择一个随机问题,如下所示:

key = random.choice(list(questions))
set = questions[key]
sample = random.sample(set, 7)

Now, you only have to check if answer is equal to key . 现在,您只需检查answer是否等于key

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM