Please let me know the English word quiz deduplication using dictionary!

Asked 2 years ago, Updated 2 years ago, 129 views

<python>
import random
dic = {'apple':'apple'', 'mango':'mango':'melon':'go':'go':'go':'tv':'TV'}
score=0
dic_list=tuple(dic.keys())
dic_answer=tuple(dic.values())
print("[English word guessing quiz]. Look at the words and write the correct Korean.]")
tmp=len(dic_list)
while score<5:
    x=random.randrange(0,tmp)
    print(dic_list[x])
    answer=input('Answer:')
    if answer == dic_answer[x]:
        score= score +1
        print('Correct. Your score is '', score, '')
    else:
        print('Incorrect. Your score is 'score.')
        break
    print('Thank you for your hard work.')

I made a simple English word quiz, but there is a disadvantage that English words that have already been released are repeated. Could you add a duplicate exclusion that excludes the words that already came out?

duplicate-elimination

2022-09-22 19:41

1 Answers

It's very simple:

Remember the question you asked, and when the question you asked is selected, you pick it again.

Question you asked = []
while score<5:
  x = random.randrange(0,tmp) #Pick a question
  If x in Question asked: continue # Make sure the question is already asked.
  # ...
  The question I asked.append(x) # Remember the question you asked.

I recommend you to do your homework by yourself. It is necessary to think alone for the level of the question-answer bulletin board and for the questioner's own improvement.


2022-09-22 19:41

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.