Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8465379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:01:36+00:00 2026-06-10T15:01:36+00:00

So as I stated before, I’m working on trying to make a multiple choice

  • 0

So as I stated before, I’m working on trying to make a multiple choice quiz. The quiz would grab 3 keys at random as the “answers”. Then the quiz would take the value of the 3 selected keys and utilize it as a “question.” I’m trying to utilize random.sample as an argument to select a value from randomly selected key values. My code is below:

import random

word_drills = {'class': 'Tell Python to make a new kind of thing.',
               'object': 'Two meanings: the most basic kind of thing, and any instance of some thing.',
               'instance': 'What you get when you tell Python to create a class.',
               'def': 'How you define a function inside a class.',
               'self': 'Inside the functions in a class, self is a variable for the instance/object being accessed.',
               'inheritance': 'The concept that one class can inherit traits from another class, much like you and your parents.',
               'composition': 'The concept that a class can be composed of other classes as parts, much like how a car has wheels.',
               'attribute': 'A property classes have that are from composition and are usually variables.',
               'is-a': 'A phrase to say that something inherits from another, as in a Salmon *** Fish',
               'has-a': 'A phrase to say that something is composed of other things or has a trait, as in a Salmon *** mouth.'}


def nodupchoice():
    key1, key2, key3 = random.sample(word_drills, 3)
    print "%s, %s, %s" % (key1, key2, key3)
    #print word_drills.random.sample[key1, key2, key3]
    #print word_drills[key1]
    #print word_drills[random.sample(key1, key2, key3)]


nodupchoice()

You will notice that I have commented out what I thought would actually give me the results I desired. Unfortunately, each one did not. Any assistance of guidance would be appreciated. Thanks again.

UPDATE

So I have incorporated the new information provided. Thank you again. This is what I came up with:

import random

word_drills = {'class': 'Tell Python to make a new kind of thing.',
               'object': 'Two meanings: the most basic kind of thing, and any instance of some thing.',
               'instance': 'What you get when you tell Python to create a class.',
               'def': 'How you define a function inside a class.',
               'self': 'Inside the functions in a class, self is a variable for the instance/object being accessed.',
               'inheritance': 'The concept that one class can inherit traits from another class, much like you and your parents.',
               'composition': 'The concept that a class can be composed of other classes as parts, much like how a car has wheels.',
               'attribute': 'A property classes have that are from composition and are usually variables.',
               'is-a': 'A phrase to say that something inherits from another, as in a Salmon *** Fish',
               'has-a': 'A phrase to say that something is composed of other things or has a trait, as in a Salmon *** mouth.'}


def nodupchoice():
    # For loop that creates a list named keys. It grabs 3 random keys from the dictionary word_drills
    keys = [x for x in random.sample(word_drills, 3)]
    # User is presented with a question. A value from the previous randomly selected keys is selected as the 'question'
    print "Question: ", word_drills[random.choice(keys)]
    # Set the variables key1, key2, & key3 to the 3 keys in the list 'keys'
    key1, key2, key3 = keys[0], keys[1], keys[2]
    # User is presented with 3 choices.
    print "\n\n(a)%s   (b)%s   (c)%s" % (key1, key2, key3)
    selection = raw_input("> ")
    print selection

nodupchoice()

The issue I’m trying to decipher now would be: How to check the users selection against what is in the dictionary word_drills. I was planning on using an if/else. If it was correct, it would notify you, else you were incorrect. Not sure how to approach this however. Just wanted to thank everyone again for the assistance, it is definitely appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T15:01:38+00:00Added an answer on June 10, 2026 at 3:01 pm

    You might want to try using random.choice() to select the key:

    keys = random.sample(word_drills, 3)
    print keys
    print word_drills[random.choice(keys)]
    

    Outputs:

    ['has-a', 'attribute', 'class']
    A phrase to say that something is composed of other things or has a trait, as in a Salmon *** mouth.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As I've stated before I'm working on a digg clone to teach myself ASP.NET
As the title states, I'm trying to resize a Texture2D before even considering SpriteBatch.Draw()
As stated in the title, I would like to know how to send a
I've read some articles before that stated you can skip the scheme from your
I have Validation working across a large form (I fire it several times before
I've stated before I'm not very good at scripting so what I have below
As I stated above, no code would be executed after my .each function. I
I have seen this question before, but none of the answers seems to work
Is there any way to cancel a RadioButton or CheckBox's change in state before
Before I ask the question let me state that I have attempted to google

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.