Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How do I get the random question to not appear again?

I can’t seem to fix how to get my questions to not appear again after they have been shown once…
Does anyone have any idea?

import random
from turtle import *
import time

def reset(x, y):
    print("Körs")
    clearscreen()

    # Här gör man det enklare för sig själv genom att kategorisera turtles.
    #Turtle()

    # Här väljer man vilken fart turtles skall ha när dom ritar
    speed(10)

    # här göms alla turtles
    hideturtle()

    # Här skriver man vad programmet heter och vilken färg bakgrunden har.
    title('Albins ofungerade spel')
    Screen().bgcolor("orange")

    quest = ('Courier', 15, 'italic')
    main = ('Courier', 25, 'italic')

    frågor = [1, 2, 3, 4, 5]

    computer_action = random.choice(frågor)

    # här ritas alla olika boxar och sidor
    l = 300
    w = 75

    penup()
    goto(-150, 100)
    pendown()

    forward(l)
    left(90)

    forward(w)
    left(90)

    forward(l)
    left(90)

    forward(w)
    left(90)

    penup()
    goto(-150, 0)
    pendown()

    forward(l)
    left(90)

    forward(w)
    left(90)

    forward(l)
    left(90)

    forward(w)
    left(90)

    penup()
    goto(-150, -100)
    pendown()

    forward(l)
    left(90)

    forward(w)
    left(90)

    forward(l)
    left(90)

    forward(w)
    left(90)

    penup()
    goto(-150, -200)
    pendown()

    forward(l)  # Forward turtle by l units
    left(90)  # Turn turtle by 90 degree

    forward(w)  # Forward turtle by w units
    left(90)  # Turn turtle by 90 degree

    forward(l)  # Forward turtle by l units
    left(90)  # Turn turtle by 90 degree

    forward(w)  # Forward turtle by w units
    left(90)  # Turn turtle by 90 degree

    def good():
        penup()
        setposition(0, -280)
        pendown()
        write("Rätt val! Tryck på skärmen för ny fråga", font=main, align='center')
        onscreenclick(reset)


    def bad():
        penup()
        setposition(0, -280)
        pendown()
        write("Fel val! Tryck på skärmen för ny fråga", font=main, align='center')
        onscreenclick(reset)



    if computer_action == 1:


        penup()
        setposition(0, 130)
        pendown()
        write("A. Danmark", font=quest, align='center')

        penup()
        setposition(0, 30)
        pendown()
        write("B. Sverige", font=quest, align='center')

        penup()
        setposition(0, -70)
        pendown()
        write("C. Finland", font=quest, align='center')

        penup()
        setposition(0, -170)
        pendown()
        write("D. Norge", font=quest, align='center')

        penup()
        setposition(0, 250)
        pendown()
        write("Vad heter det största landet i Norden?", font=main, align='center')

        onkeypress(good, 'b')
        onkeypress(bad, 'd')
        onkeypress(bad, 'c')
        onkeypress(bad, 'a')
        listen()



    elif computer_action == 2:

        penup()
        setposition(0, 130)
        pendown()
        write("A. Java", font=quest, align='center')

        penup()
        setposition(0, 30)
        pendown()
        write("B. C++", font=quest, align='center')

        penup()
        setposition(0, -70)
        pendown()
        write("C. Python", font=quest, align='center')

        penup()
        setposition(0, -170)
        pendown()
        write("D. LUA", font=quest, align='center')

        penup()
        setposition(0, 250)
        pendown()
        write("Vad är William och Svens favorit språk?", font=main, align='center')

        onkeypress(good, 'd')
        onkeypress(bad, 'a')
        onkeypress(bad, 'c')
        onkeypress(bad, 'b')
        listen()

    elif computer_action == 3:

        penup()
        setposition(0, 130)
        pendown()
        write("A. Fredrik Reignfeldt", font=quest, align='center')

        penup()
        setposition(0, 30)
        pendown()
        write("B. Magdalenda Andersson", font=quest, align='center')

        penup()
        setposition(0, -70)
        pendown()
        write("C. Sven Blomqvist", font=quest, align='center')

        penup()
        setposition(0, -170)
        pendown()
        write("D. Martin Nilsson", font=quest, align='center')

        penup()
        setposition(0, 250)
        pendown()
        write("Vad heter Sveriges statsminister?", font=main, align='center')

        onkeypress(good, 'b')
        onkeypress(bad, 'a')
        onkeypress(bad, 'c')
        onkeypress(bad, 'd')
        listen()

    elif computer_action == 4:

        penup()
        setposition(0, 130)
        pendown()
        write("A. Joe Biden", font=quest, align='center')

        penup()
        setposition(0, 30)
        pendown()
        write("B. Bill Clinton", font=quest, align='center')

        penup()
        setposition(0, -70)
        pendown()
        write("C. Donald Trump", font=quest, align='center')

        penup()
        setposition(0, -170)
        pendown()
        write("D. Albin Winqvist", font=quest, align='center')

        penup()
        setposition(0, 250)
        pendown()
        write("Vad heter USA's president?", font=main, align='center')

        onkeypress(good, 'a')
        onkeypress(bad, 'd')
        onkeypress(bad, 'c')
        onkeypress(bad, 'b')
        listen()

    elif computer_action == 5:

        penup()
        setposition(0, 130)
        pendown()
        write("A. Borgarskolan", font=quest, align='center')

        penup()
        setposition(0, 30)
        pendown()
        write("B. Procivitas", font=quest, align='center')

        penup()
        setposition(0, -70)
        pendown()
        write("C. Bernadottegymnasiet", font=quest, align='center')

        penup()
        setposition(0, -170)
        pendown()
        write("D. Pauliskolan", font=quest, align='center')

        penup()
        setposition(0, 250)
        pendown()
        write("Vad är Malmös bästa skola?", font=main, align='center')

        onkeypress(good, 'c')
        onkeypress(bad, 'a')
        onkeypress(bad, 'd')
        onkeypress(bad, 'b')
        listen()








    onscreenclick(reset)


onscreenclick(reset)
done()

Sorry if my code seems sloppy, or anything similar, but I just need help with how to make a question not appear again after it appeared once.
And I know turtle might not be the best, but it’s the only thing I could think of when doing this simple project.
Thanks for any help I get, it means alot!

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Take this line of code:

frågor = [1, 2, 3, 4, 5]

…and put it outside of the reset() function – i.e., into global space

Then…

computer_action = random.choice(frågor)
frågor.remove(computer_action)

In other words, you make a random selection from the list then you remove whatever you selected.

The problem is that you’ll only be able to do this len(frågor) times. You’ll need to figure out how to cope with that eventuality

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading