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 can i random.choice a question without the answer for a discord robot quiz game?

I just started learning how to code ( in python ) and i was wondering how can I randomly ask questions for a quiz without the answer that follows?

For example, I’d want the robot to ask ‘What’s the capital of France?’ but without it saying ‘Paris’?

questions = [("What’s the capital of France?", "Paris"), ("Who painted the Mona Lisa?", "Da Vinci")]

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

Ty 🙂

>Solution :

random.choice will just return a tuple (since those are the items in your list). So you can access just the first element while printing by doing [0].

For example, print(random.choice(questions)[0]).

In the larger program you’d want to assign the tuple to a variable, so that later you fetch the answer for the same question (by using [1]) instead of randomly selecting again.

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