2021年1月28日星期四

How do I change the order of solutions with my Discord bot?

Some time ago I received help here. This code is about making replies always appear in a different order in a message. But in the process everything gets mixed up. A random.choice event for each of the answers (A, B, C, D) and the questions was created. I would like however only that the answer possibilities remain random, speak:

1st attempt:

(9 is correct here)

A) 9

B) 8

C) 7

The answer given is "A", correct.

2nd run-up:

A) 8

B) 9

C) 7

Now "B" is given as the answer, that should also be counted as correct. How do I proceed?

My code:

        question_one = "How many lives do cat's have?"          answers_one = {"9": "A", "1": "B", "10": "C"}              questions = {question_one: {"9": answers_one}, "Is this working now?": {"A": {"Yes!": "A",                                                                                         "No!": "B", "Maybe...": "C"}}}            # get a question          question = random.choice(list(questions.keys()))          data = questions.get(question)          correct_answer = list(data.keys())[0]          answers = list(list(data.values())[0].items())          question_msg = ""          answers_msg = ""            numbers_list = []          answers_list = []            for answer, number in answers:              numbers_list.append(number)              answers_list.append(answer)            while numbers_list:              num = numbers_list              ans = random.choice(answers_list)              answers_msg += f "**{num}) {ans}**\n"              answers_list.remove(ans)              numbers_list.remove(num)  

My attempt was simply to remove the random function, but accordingly there is then no more list and nothing can be selected. My attempt to create a list also failed.

https://stackoverflow.com/questions/65938337/how-do-i-change-the-order-of-solutions-with-my-discord-bot January 28, 2021 at 09:45PM

没有评论:

发表评论