w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories

python quiz, picking a random query from a list


Is something like this what you're looking for? It repeats the set of questions until the amount of right answers is >= 5. However, the way you've written it, it repeatedly asks the same question until you get it right. Is this what you intended?

import random

def questionchal(questionText, answer):
    if input(questionText + ' ') == answer:
        return True

def gamelist():
    game = input('select a game, game 1, game 2 or
game 3 ')
    if game == 'game 1':
        print('okay')
    if game == 'game 2':
        print('okayy')
    if game == 'game 3':
        print('okayyy')

questionsright = 0

#creates a list of questions and their answers
questionList = [
        ('What is my name?' , 'john'),
        ('Where do i live?' , 'uni'),
        ('Am i happy or sad?' , 'happy'),
        ('Am i hungry or full?' , 'hungry'),
        ('Am i alseep or awake?' , 'awake'),
        ('how old am i?' , '19')
    ]

if __name__ == "__main__":
    while questionsright < 5:
        for questionText, answer in questionList:
            while questionchal(questionText,
answer) is not True:
                print('Wrong, heres another
question!')
            print('Correct! Next question!')
            questionsright +=1
            print(questionsright)

    else:
        print('Thanks for playing')
        gamelist()

and if you want it to skip to the next question if the user gets it wrong, you can do this:

if __name__ == "__main__":
    while questionsright < 5:
        for questionText, answer in questionList:
            if questionchal(questionText, answer):
                print('Correct! Next question!')
                questionsright +=1
                print(questionsright)
            else:
                print('Wrong, heres another
question!')

    else:
        print('Thanks for playing')
        gamelist()

Categories : Python

Related to : python quiz, picking a random query from a list
Python - Picking a Random Column or Row from 3x3 NP Array
Simple case, use np.random.randint(0, 3, 2) to make two random numbers between 0 and 3. Then you can use this to index your array, if you convert it to a tuple: rand_point = np.random.randint(0, 3, 2) grid[tuple(rand_point)] = input("Place a number at %s: " % rand_point) Or you could generate the two numbers separately (this would be important if your array is not square): nrows, ncols = grid

Categories : Python
Picking Random Numbers in c#
Use a proper shuffle algorithm, such as Knuth's (aka Fisher-Yates): /// <summary>Used to shuffle collections.</summary> public class Shuffler { /// <summary>Shuffles the specified array.</summary> /// <typeparam name="T">The type of the array elements.</typeparam> /// <param name="array">The array to shuffle.</param> public void Sh

Categories : C#
Picking random winners
Easy one : At the start of each day, pick three hours, randomly, like : 11:45 AM 09:17 PM 11:17 PM Store theses info in a database, mentioning if it's already picked or not. When someone "pick" a "instant-prize", check if one of theses dates is both : Non picked Before "now" If so, mark it picked, and give him the prize. Of course, if your last date is "11:59PM", chances are nobody will

Categories : PHP
Picking a random element from a hash set
I recently stumbled upon the same problem. here is what i came up with #include <unordered_set> #include <iostream> using namespace std; int main() { unordered_set<int> u; int ins = 0; for (int i=0; i<30; i++) { // something to fill the test set ins += i; ins %= 73; u.insert(ins); } cout << "total number of buckets: " << u.bucket_count() <<

Categories : Objective C
Picking random binary flag
Assuming I've correctly understood your intent, if your definition of "elegant" includes table lookups the following should do the trick pretty efficiently. I've written enough to show how it works, but didn't fill out the entire table. Also, for Objective-C I recommend arc4random over using rand. First, construct an array whose indices are the possible t values and whose elements are arrays of

Categories : Objective C
© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.