dimanche 3 mai 2020

random.choice without duplicates in tuple in python

I'm making a simple translation game, and I don't want duplicate "quiz" when I run this code.

Here is my current code that asks duplicate questions:

sentence = ("naranja", "azul", "llamada", "blanco", "negro", "cancion", "rojo", "hielo", "cara")

answer = ("orange", "blue", "call", "white", "black", "sing", "red", "ice", "face")

num = 0

while num <= len(sentence):
    quiz = random.choice(sentence)
    order = sentence.index(quiz)
    print(quiz)
    a = input("Translate in English : ")
    if a == answer[order]:
        print("Correct!")

    else :
        print("Wrong!", answer[order])



Aucun commentaire:

Enregistrer un commentaire