订单号与索引号不同

时间:2018-06-02 13:32:58

标签: python python-2.7

我有这种情况,我必须选择一个单词,所以程序将打印出单词的含义,但订单号与索引号x不匹配,例如(1,2,3)但索引是(0 ,3,7),下次可能是(1,2,3)和索引(1,3,5),请你帮我解决这个问题。我想要任何解决方案,如果选择第二个单词,我想要它的含义。谢谢umer selmani

"C:\Users\Umer Selmani\venv\Scripts\python.exe" "C:/Users/Umer Selmani/.PyCharm2017.3/config/scratches/scratch_10.py"
Please select one of these options: 1
What word you want to add? ball
add the meaning of the word: round shape item
would you like to continue or exit?
1.contine
2.exit
>>> 1
Please select one of these options: 1
What word you want to add? cactus
add the meaning of the word: flower type
would you like to continue or exit?
1.contine
2.exit
>>> 1
Please select one of these options: 1
What word you want to add? fall
add the meaning of the word: season
would you like to continue or exit?
1.contine
2.exit
>>> 1
Please select one of these options: 2
select the words, you wantll
1 ball 0
2 fall 2
would you like to continue or exit?
1.contine
2.exit
>>> 2
bye

这里你去,输出。

@Directive({
  selector: '[ngxInit]',
})
export class NgxInitDirective {
  constructor(
    private templateRef: TemplateRef<any>,
    private viewContainer: ViewContainerRef) {
  }

  @Input() set ngxInit(val: any) {
    this.viewContainer.clear();
    this.viewContainer.createEmbeddedView(this.templateRef, {ngxInit: val});
  }
}

1 个答案:

答案 0 :(得分:0)

与其他人评论一样,Python 2中默认不对字典进行排序。然后,代码中唯一真正的问题是游戏功能的第一行。尝试这样的事情:

empt_list=[]
empt_list_meaning=[]
def game():
        # Dict not needed
        #empt_dict = dict(zip(empt_list, empt_list_meaning))
        # add clarification of what the options are
        print 'Press 1 to add a word or 2 to search for a word.'
        a_options = input("Please select one of these options: ")
        if a_options == 1:
            a_newword = str(raw_input("What word you want to add? "))
            empt_list.append(a_newword)
            a_newword_meaning=str(raw_input("add the meaning of the word: "))
            empt_list_meaning.append(a_newword_meaning)

        elif a_options == 2:
            a_select_word = raw_input("select the words, you want")
            # Use enumerate instead of variable here
            #zero = 0
            for zero, word in enumerate(empt_list):
                if a_select_word in word:
                    #zero += 1
                    # Index the lists you already have instead of indexing the keys of an unordered dict
                    print zero, word, empt_list_meaning.index(word)
                    print empt_list_meaning[zero]

        print ("would you like to continue or exit?\n1.contine\n2.exit")
        now = input(">>> ")
        if now == 1:
            game()
        else:
            print "bye"
game()